How to remove double spaces with regular expression

How to remove double spaces with regular expression

To remove, use the following code

$result = preg_replace('/\s+/', ' ',$text);

The first parameter of the function is "\s". It matches any "whitespace" character: a space (" "), tab (t), newline (n), or carriage return (r).
Next comes the "+", which means one or more matches.

Posts on similar topics

Are you having problems with your WordPress site? Do you need additional functionality? A custom plugin or a new page?
Then write to me via the feedback form, and I will try to help you.

Write a comment

Your email address will not be published. Required fields are marked *