note 91828 added to function.nl2br
| From: | leaf at leafo dot net | Date: | Fri, 26 Jun 2009 20:02:48 +0000 |
| Subject: | note 91828 added to function.nl2br | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-157616@lists.php.net to get a copy of this message | ||
for the <pre> tag problem, the reason why nl2br does that is because it converts all \n to
<br />\n
(see the extra \n there)
an easy hack is to use strtr to replace all \n with just <br />
eg.
<?php
function mynl2br($text) {
strtr($text, array("\n" => '<br />', "\r\n"
=>'<br />'));
}
?>
very simple and very fast. the only disadvantage is that anyone reading your nl2br'd html will
see it all on one line.
----
Server IP: 64.71.164.2
Probable Submitter: 24.188.24.105
----
Manual Page -- http://www.php.net/manual/en/function.nl2br.php
Edit -- https://master.php.net/note/edit/91828
Del: integrated -- https://master.php.net/note/delete/91828/integrated
Del: useless -- https://master.php.net/note/delete/91828/useless
Del: bad code -- https://master.php.net/note/delete/91828/bad+code
Del: spam -- https://master.php.net/note/delete/91828/spam
Del: non-english -- https://master.php.net/note/delete/91828/non-english
Del: in docs -- https://master.php.net/note/delete/91828/in+docs
Del: other reasons-- https://master.php.net/note/delete/91828
Reject -- https://master.php.net/note/reject/91828
Search -- https://master.php.net/manage/user-notes.php