I can't replicate the problem here:
$x = "this \n \t\t \n works.";
var_dump(preg_replace('/\s\s+/', ' ', $x));
// string(11) "this works."
I'm not sure if it was just a transcription error or not, but in your example, you're using a single-quoted string. \n
and \t
are only treated as new-line and tab if you've got a double quoted string. That is:
'\n\t' != "\n\t"
Edit: as Codaddict pointed out, \s\s+
won't replace a single tab character. I still don't think using \s+
is an efficient solution though, so how about this instead:
preg_replace('/(?:\s\s+|\n|\t)/', ' ', $x);