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

From: Date: Thu, 06 Dec 2001 16:41:08 +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-76903@lists.php.net to get a copy of this message
using "\n" as your replacement text will do it....however, if you want a newline in the html, then you'll want <br>... and as far as the advanced replace, make an array of search patterns, in this case two. your first pattern will be "/[ ]+\n+[ ]+/" with a replacement of a single newline...then the second will be the previous regex.....check out php.net for help with syntax and using arrays with preg_* functions....the first should catch all situations of a series of spaces [with at least one newline in between them] and substitute a newline..... check out mastering regular expressions as well.....its worth the money.... jack -----Original Message----- From: Ken [mailto:kenzo@free-music.com] Sent: Thursday, December 06, 2001 3:08 AM To: Jack Dempsey; liljim; PHP list Subject: RE: [PHP] Reg ex help-Removing extra blank spaces before HTML output At 02:43 PM 12/5/01 -0500, Jack Dempsey wrote: >$t = preg_replace('/\s+/',' ',$text); One more thing: How do I replace with newline instead of a space? I read through the manuals but couldn't grasp how to do this. \n didn't cut it. And, more advanced - The above replaces any groups of 2 or more blanks (newlines, spaces, tabs) with a single blank. Is there an easy way to replace them with EITHER a space or a newline, depending on whether any newlines were present in the input? I.e. bbbbbbbbbbbbbb would be replaced with b, but bbbbbnbbbbbnbbbb would be replaced with n. Right now the issue is that I'm sometimes getting results that have no line breaks for a really long time, and I know there are reasons to try to avoid individual lines of HTML longer than 200 characters. Thanks! - Ken kenzo@free-music.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#76903) next »