Se vuoi "collassare" gli spazi:

codice:
$str = "    ciao a tutti\t\t belli e brutti  \t!";
$str = preg_replace("/([ \t]+)/", " ", trim($str));
ciao