note 56967 deleted from function.nl2br by sean
| From: | sean@php.net | Date: | Tue, 20 Sep 2005 17:10:31 +0000 |
| Subject: | note 56967 deleted from function.nl2br by sean | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-95488@lists.php.net to get a copy of this message | ||
Note Submitter: info at antonioceccatelli dot it
Reason: bad code
----
I wrote this two functions that are very usefull with mysql BLOB type.
function br2nl4sql($string)
{
// Replace Cr & Lf with a "<br />"
$string = str_replace("\r\n", '<br />', $string);
return $string;
}
function br2nl4html($string)
{
// Replace "<br />" with CR&LF
$string = str_replace("<br />","\n", $string);
return $string;
}
usage:
when you read a field from mysql use this:
$note = br2nl4html(stripslashes($row['note'])));
when you want to save form data to mysql, use this:
$note = br2nl4sql(addslashes($_POST[array_form][note]));