View Single Post
Old 12-10-2012, 07:02 AM   PM User | #1
shadowsai
New Coder

 
Join Date: Dec 2009
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
shadowsai is an unknown quantity at this point
PHP Whitespace Replacement

Hello All!
I need something that will allow me to replace each space character with   but only when the amount of space characters is greater than (or equal to) 2.

For example:
Code:
This     had 5 spaces
Would become this.
Code:
This     had 5 spaces
I thought of using regex, like below, but it doesn't allow me to match each space character. I don't know of a way to "count" the amount of matched characters.
PHP Code:
preg_replace("/[ ]{2,}/"" "$string
Any help is appreciated!

Edit: Sorry, I only mean space. As in, " ".

Last edited by shadowsai; 12-10-2012 at 07:06 AM..
shadowsai is offline   Reply With Quote