$string = \"My text has so much whitespace
Plenty of spaces and tabs\";
echo preg_replace(\"/\\s\\s+/\", \" \", $string);
this would COMPLETELY MINIFY the entire string (such as a large blog article) yet preserving all HTML tags in place.
$email_body = str_replace(PHP_EOL, ' ', $email_body);
//PHP_EOL = PHP_End_Of_Line - would remove new lines too
$email_body = preg_replace('/[\r\n]+/', "\n", $email_body);
$email_body = preg_replace('/[ \t]+/', ' ', $email_body);