Forum Moderators: coopster

Message Too Old, No Replies

changing <ENTER>'s in a textarea to <BR>'s

         

partha

4:46 pm on Apr 20, 2005 (gmt 0)

10+ Year Member



I have a script that takes whatever I enter in a <textarea> and inserts it in a mysql db.

if I enter:

stuff
cool
bar

and then output it from the db, I get:

stuff cool bar

How do I make it replace the newlines/linebreaks/whatever they're called with <BR>s so it will show up correctly?

dreamcatcher

4:49 pm on Apr 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi partha,

When you output use the nl2br() function. Lets say your data comes via the $row['message'] variable from the database.

echo nl2br($row['message']);

Hope that helps.

dc

partha

5:04 pm on Apr 20, 2005 (gmt 0)

10+ Year Member



yeah I already tried that and it didn't make a difference for some reason...so I was thinking maybe the output from the textarea doesn't have newlines or something?

bomburmusicmallet

5:47 pm on Apr 20, 2005 (gmt 0)

10+ Year Member



Hi Partha,

I picked this up somewhere along the lines:


<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') //if you submited the form then
{
$message = $_POST["message"]; //message is the text field in the form
$message=eregi_replace(chr(13),"<br>",$message); // replace chr(13) ( Line
Break Char ) with <br> ( Line break html code )
echo $message; // print the variable
}
?>

HTH, Jenny