Page 1 of 1

String Manipulation

Posted: Mon Feb 21, 2005 5:42 pm
by hawleyjr
I have a string such as:

Code: Select all

$str = 'The car is                                     red';

I need to remove the additional double spaces. However using:

Code: Select all

str_replace('  ', ' ',$str);

Doesn't cut it because I'm still left with double spaces. I really don't want to toss the string in a loop. any suggestions?

Posted: Mon Feb 21, 2005 5:57 pm
by feyd

Code: Select all

$str = preg_replace('#ї ]+#', ' ', $str);

Posted: Mon Feb 21, 2005 6:05 pm
by hawleyjr
Thanks Feyd, works great.