Replace any non-space whitespace, with a space
<?php
$str = " This line contains\tliberal \r\n use of whitespace.\n\n";
$str = preg_replace('/[\n\r\t]/', ' ', $str);
// Echo out: 'This line contains liberal use of whitespace.'
echo "<pre>{$str}</pre>";
?>
Related examples in the same category