Re: html text area and mysql text fields
| From: | Matthew Sims | Date: | Tue, 27 Jul 2004 21:55:23 +0000 |
| Subject: | Re: html text area and mysql text fields | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-192032@lists.php.net to get a copy of this message | ||
> Hi,
>
> If I have a html textarea for inputting text into a database text field
> how can I keep the formatting of the entered text?
>
> i.e. on the html textarea if the user enters carriage returns i.e. a new
> paragraph I want that to go into the database then when I retrieve it and
> display it on a normal html page I want to keep those carriage returns!
>
> Thanks
>
> Matt
Before injecting textarea data into a DB use this:
$_POST["textarea"] =
str_replace("\n","<br>",$_POST["textarea"]);
When retrieving data from the DB for a textarea use this before displaying:
$_POST["textarea"] =
str_replace("<br>","\n",$_POST["textarea"]);
--
--Matthew Sims
--<http://killermookie.org>