I'm trying to remove excess whitespace from a string like this:
hello world
to
Anyone has any idea how to do that in PHP?
With a regexp :
preg_replace('/( )+/', ' ', $string);
If you also want to remove every multi-white characters, you can use s (s is white characters)
preg_replace('/(s)+/', ' ', $string);
1.4m articles
1.4m replys
5 comments
57.0k users