cool, glad you got it working...if you think there's a bug with using / and
| you might want to see if you can replicate the problem, and if its really
a bug, submit guess is that it was just a typo or something


-----Original Message-----
From: Ken [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 06, 2001 5:13 PM
To: Jack Dempsey; PHP list
Subject: RE: [PHP] Reg ex help-Removing extra blank spaces before HTML

OK, this time the \n worked.  The only thing I changed was using /
delimiters instead of | delimiters in the search string.  No idea if/why
that would affect anything in the replacement string.

Anyway, I finally came up with exactly what I wanted:
preg_replace(array("/\s*\n+\s*/", "/[ ]+/"), array("\n", " "), $input);

All padding (defined as any series of spaces, newlines and sometimes tabs)
is removed from $input, but always leaving at least a space or a newline in
its place.  If there were any newlines in the "padding", then a newline is
left.  If there weren't, then a space is left.

Thanks for the help!


At 04:40 PM 12/6/01 -0500, Jack Dempsey wrote:
>one call to preg_replace...if you check out, you'll
>what i mean...use arrays...
>and as long as you have them ordered in the right way, it'll execute them
>that order, so by the time the \s replace comes up all your 'bbbnbb' will
>fixed...problem then is that those newlines would get caught by the \s and
>get switched to, if you want them to stay, then use [ ] to
>represent a space instead of \s...might want [ \t] to catch tabs as well...

PHP General Mailing List (
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to