RE: [PHP] Line breaks...
| From: | Jon Haworth | Date: | Tue, 16 Apr 2002 08:50:00 +0000 |
| Subject: | RE: [PHP] Line breaks... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-93152@lists.php.net to get a copy of this message | ||
Hi Phil,
> I have a form inserting data into a database. I'm using
> nl2br to add <br> to the data enetered where appropriate.
> The data is then pulled out of the database and inserted
> into text fields for editing.
> Can anyone tell me how to remove the <br> tags while
> maintaining the line breaks in the text field?
Don't use nl2br when you're storing the data, use it when you're displaying
it.
// write data to table
$s = "INSERT INTO foo SET bar = 'some text \n with a line break'";
$q = mysql_query ($s);
// read data from table
$s = "SELECT foo FROM bar";
$q = mysql_query ($s);
$r = mysql_fetch_array ($q);
echo "this is ". nl2br ($r["foo"]);
HTH
Jon