RE: [PHP] Reg ex help-Removing extra blank spaces before HTML output

From: Date: Wed, 05 Dec 2001 19:43:52 +0000
Subject: RE: [PHP] Reg ex help-Removing extra blank spaces before HTML output
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-76770@lists.php.net to get a copy of this message
actually it does... james' solution will work but I forgot to mention a \s is whitespace, not a space, therefore it will get tabs, newlines, and spaces. look at http://www.cs.tut.fi/~jkorpela/perl/regexp.html " \s matches any whitespace character (space, tab, newline)" therefore my suggestion works: $t = preg_replace('/\s+/',' ',$text); its quicker to code, easier to understand, and will run faster because it doesn't have to match and remember or do alternation... jack -----Original Message----- From: Ken [mailto:kenzo@free-music.com] Sent: Wednesday, December 05, 2001 2:01 PM To: Jack Dempsey Subject: RE: [PHP] Reg ex help-Removing extra blank spaces before HTML output At 10:57 AM 12/5/01 -0500, Jack Dempsey wrote: >a space (\s is from perl) Ah, OK, yours doesn't deal with newlines. From list member "James", a solution that does: ----- From: "liljim" <liljim@liljim.co.uk> The example Jack gave you will clear up spaces well, though to get both newlines and spaces into one: $input = preg_replace("/([ ]|\n){1,}/", "\\1", $input); ----- Thanks again! - Ken kenzo@free-music.com

« previous php.general (#76770) next »