note 43500 added to function.nl2br

From: Date: Wed, 23 Jun 2004 11:27:45 +0000
Subject: note 43500 added to function.nl2br
Groups: php.notes 
Request: Send a blank email to php-notes+get-71545@lists.php.net to get a copy of this message
I have an admin area, where users can enter text including html. I want the content to be nl2br'ed, but when they enter something like this: <b>hello</b> this content is on multiple lines <table> <tr> <td>this is a problem</td> </tr></table> Each line receives a br, which screws the format of the table up. So, this code: <? $nobr = false; $content = ""; $tmp_content = explode("\n",$row['content']); foreach($tmp_content as $line) { if(strpos($line,"<nobr>")!==false) { $nobr = true; } else if(strpos($line,"</nobr>")!==false) { $nobr = false; } else { $content .= $line; if(!$nobr) { $content .= "<br />\n"; } } } ?> will nl2br everything that's not enclosed in <nobr>, </nobr> tags. The user can now enter <b>hello</b> this content is on multiple lines <nobr> <table> <tr> <td>this is a problem</td> </tr></table> </nobr> and the script will add a <br /> after the first few lines, but not inside the <nobr> tags. hope someone finds it helpful. ---- Manual Page -- http://www.php.net/manual/en/function.nl2br.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+43500 Delete -- http://master.php.net/manage/user-notes.php?action=delete+43500&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+43500&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#71545) next »