October 26th, 2000, 12:48 PM
i have a html text area that i'm inserting into a mySQL database. before it's submitted, i would like to allow formatting in that text area, so i want to replace all carriage returns with <br> tags.
how can i do this?
October 26th, 2000, 01:24 PM
If your textarea is named summary
then before your run your query
$summary = nl2br($summary);
October 27th, 2000, 10:20 AM
Just note that this doesn't "replace" the newlines with <BR>, it simply adds the <BR> in before the newlines. If you need them actually replaced, use something like this..
$summary = str_replace("n","<BR>",$summary);
The output will look the same in your browser no matter which method you use. It'll just change how your source code looks.