note 70692 deleted from function.nl2br by colder
| From: | colder@php.net | Date: | Tue, 24 Oct 2006 07:49:34 +0000 |
| Subject: | note 70692 deleted from function.nl2br by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-119058@lists.php.net to get a copy of this message | ||
Note Submitter: http://www.havarnielsen.com
Reason: bad code
----
// nl2br doesn't REPLACE the newline characters with a <br> tag. It just adds a
<br> tag in front of it.
// This function does REPLACE CRLF and newlines with a <br> tag.
function my_nl2br($str)
{
$retvar = str_replace("\n\r", '<br />', $str);
$retvar = str_replace("\n", '<br />', $str);
return $retvar;
}
// And a function to go the oppisite way.
function br2nl($str)
{
return preg_replace('!<br.*>!iU', "\n", $str);
}