Get rid of extra spaces using PHP's preg_replace
Right there in the examples for the php function preg_replace was how to strip whitespace from a string:
$str = preg_replace('/\s\s+/', ' ', $str);
Ereg replace looks prettier:
$string = trim(ereg_replace(' +', ' ', $string));
However, Agaric has read in several places that preg_replace tends to be faster.