Tandem Posted January 8, 2007 Share Posted January 8, 2007 I need to remove all whitespace from a string, is there a function that does it? If not what is the regex to detect if a strign contains any whitespace?Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/33388-removing-all-whitespace-from-a-string/ Share on other sites More sharing options...
matto Posted January 8, 2007 Share Posted January 8, 2007 [code]$new_string = trim(str_replace(" ","",$string));[/code] Link to comment https://forums.phpfreaks.com/topic/33388-removing-all-whitespace-from-a-string/#findComment-156054 Share on other sites More sharing options...
Tandem Posted January 8, 2007 Author Share Posted January 8, 2007 Thanks very much! Link to comment https://forums.phpfreaks.com/topic/33388-removing-all-whitespace-from-a-string/#findComment-156056 Share on other sites More sharing options...
effigy Posted January 8, 2007 Share Posted January 8, 2007 matto's code will take care of spaces, but the term "whitespace" encompasses more--new lines, tabs, etc. Try the regex [tt]/\s+/[/tt]. Link to comment https://forums.phpfreaks.com/topic/33388-removing-all-whitespace-from-a-string/#findComment-156057 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.