n00b n00b - 9 months ago 28
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!


Remove spaces and tabs

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

Remove only spaces

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