Reputation: 6562
Why is this very simple preg_replace is returning null ?
preg_replace('[\s]+', '', "test test")
the idea was to remove spaces.
Upvotes: 0
Views: 239
Reputation: 91385
Another way with delimiter [
& ]
:
preg_replace('[\s+]', '', "test test")
Upvotes: 0
Reputation: 174706
You forget to add delimiters.
preg_replace('~\s+~', '', "test test");
And also it's better to use \s+
instead of [\s]+
in your pattern.
Upvotes: 5
Reputation: 43481
Your regex is wrong, there are no beginning and ending slashes:
preg_replace('/[\s]+/', '', "test test");
Upvotes: 2