n00b n00b - 5 months ago 14
PHP Question

PHP Regexp - Remove redundant spaces but keep line breaks

I'm looking for a regular expression that removes redundant (two or more) spaces but keeps line breaks.

Any idea how that would work?

Thanks in Advance!

Answer

Remove spaces and tabs

preg_replace("/[ \t]+/", " ", $myval);

Remove only spaces

preg_replace("/[ ]+/", " ", $myval);