Page 1 of 1

strip whitespace?

Posted: Fri Feb 18, 2005 2:58 pm
by Pyrite
Ok, I know about trim(), ltrim() and rtrim(). But is there a way to just strip ALL whitespace from a string?

Posted: Fri Feb 18, 2005 3:03 pm
by John Cartwright
preg_replace(), str_replace() :?

take your pick, I would probably use str_replace since this a real simple and regex would be overkill

something along the lines of

Code: Select all

$str = str_replace(" ","",$str);

Posted: Fri Feb 18, 2005 4:03 pm
by feyd
well.. since you say whitespace..

Code: Select all

$str = preg_replace('#\s+#s', '', $str);