Stripping whitespace

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
HiddenS3crets
Forum Contributor
Posts: 119
Joined: Fri Apr 22, 2005 12:23 pm
Location: USA

Stripping whitespace

Post by HiddenS3crets »

Is there any quick way to replace x amount of spaces with only one?

ex. (assume '-' is one space)
Before: This is----a---test------string
After: This is a test string
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

sure:

Code: Select all

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