To remove multiple occurences of whitespace characters in a string an convert them all into single spaces, use this: <? $text = preg_replace('/\s+/', ' ', $text); ?>