note 76431 added to function.nl2br

From: Date: Sun, 15 Jul 2007 04:46:45 +0000
Subject: note 76431 added to function.nl2br
Groups: php.notes 
Request: Send a blank email to php-notes+get-128533@lists.php.net to get a copy of this message
After realizing this would be a problem in allowing users to enter select HTML tags at http://www.VideoSift.com I came up with this simple, yet somewhat elegant solution to <br /> being inserted into the middle of HTML tags containing newlines (e.g., "<a \n href=..." becomes "<a <br /> href=..."). There are probably other solutions somewhere on this quite lengthy page, but in case not, here's my contribution: <?php public static function html_nl2br($i_str) { $i_str = str_replace("\r\n", "\n", $i_str); $i_str = str_replace("\r", "\n", $i_str); $lines = split("\n", $i_str); $i_str = ''; foreach ($lines as $index => $line) { if (!(strrpos($line, '<') > strrpos($line, '>'))) $lines[$index] .= '<br />'; } return implode(' ', $lines); } ?> ---- Server IP: 208.69.120.35 Probable Submitter: 68.4.78.74 ---- Manual Page -- http://www.php.net/manual/en/function.nl2br.php Edit -- https://master.php.net/note/edit/76431 Del: integrated -- https://master.php.net/note/delete/76431/integrated Del: useless -- https://master.php.net/note/delete/76431/useless Del: bad code -- https://master.php.net/note/delete/76431/bad+code Del: spam -- https://master.php.net/note/delete/76431/spam Del: non-english -- https://master.php.net/note/delete/76431/non-english Del: in docs -- https://master.php.net/note/delete/76431/in+docs Del: other reasons-- https://master.php.net/note/delete/76431 Reject -- https://master.php.net/note/reject/76431 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128533) next »