n00b n00b - 1 year ago 93
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 Source

Remove spaces and tabs

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

Remove only spaces

preg_replace("/[ ]+/", " ", $myval);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download