Use preg_replace() and instead of [ ] use s:
preg_replace()
[ ]
s
$output = preg_replace('!s+!', ' ', $input);
From Regular Expression Basic Syntax Reference:
d, w and s Shorthand character classes matching digits, word characters (letters, digits, and underscores), and whitespace (spaces, tabs, and line breaks). Can be used inside and outside character classes.
d, w and s
Shorthand character classes matching digits, word characters (letters, digits, and underscores), and whitespace (spaces, tabs, and line breaks). Can be used inside and outside character classes.
2.1m questions
2.1m answers
60 comments
57.0k users