$string = \"My text has so much whitespace
Plenty of spaces and tabs\";
echo preg_replace(\"/\\s\\s+/\", \" \", $string);
//Newline and tab space to single space
$from_mysql = str_replace(array("\r\n", "\r", "\n", "\t"), ' ', $from_mysql);
// Multiple spaces to single space ( using regular expression)
$from_mysql = ereg_replace(" {2,}", ' ',$from_mysql);
// Replaces 2 or more spaces with a single space, {2,} indicates that you are looking for 2 or more than 2 spaces in a string.