<?php $str = "This is a string with spaces, tabs and newlines present"; $stripped = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $str); echo $str; echo "\n---\n"; echo "$stripped"; ?> This is a string with spaces, tabs and newlines present --- This is a string with spaces, tabs and newlines present