The common solution to turn multiple white spaces into one white space is by using regular expression like this:
preg_replace('/\s+/',' ',$str);
However, regex tends to be slow because it has to load the regular expression engine. Are there non-regex methods to do this?