note 91828 deleted from function.nl2br by googleguy
| From: | googleguy@php.net | Date: | Thu, 13 Jun 2013 11:10:44 +0000 |
| Subject: | note 91828 deleted from function.nl2br by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-195180@lists.php.net to get a copy of this message | ||
Note Submitter: leaf at leafo dot net
----
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) {
return strtr($text, array("\r\n" => '<br />', "\r" =>
'<br />', "\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.