I think there's also:
function removeExtraSpaces($str) {
//remove whitespace from start and end
$str = trim($str);
//convert whitespace in between to a single space each
return preg_replace("/[\\\\n\\\\r\\\\t ]+/", " ", $str);
}
then you can simply use this function on your strings.
I used this myself to prevent spoofing of nicknames since extra whitespace is not shown when a page is displayed.
EDIT:
hmm... think there's a bug, so fixed it.