String Manipulation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

String Manipulation

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$str = preg_replace('#ї ]+#', ' ', $str);
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Thanks Feyd, works great.
Post Reply