Shoutbox

PHP textarea help - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: PHP textarea help (/showthread.php?tid=53102)

PHP textarea help by Ezra on 11-19-2005 at 03:43 PM

I have a textarea en I want to add the inputted text into a database and after that display it on a website, but the formatting like {ENTER} gets lost, how can I change the {ENTER} to a <br> to save the formatting?

TIA


RE: PHP textarea help by -dt- on 11-19-2005 at 03:57 PM

do something like

code:
$message = $_POST['textarea'];
$message = str_replace("\n",'<br>',$message);


and it should turn all newlines into <br>'s
RE: PHP textarea help by L. Coyote on 11-19-2005 at 04:04 PM

quote:
Originally posted by -dt-
do something like
code:
$message = $_POST['textarea'];
$message = str_replace("\n",'<br>',$message);


and it should turn all newlines into <br>'s
Why not use PHP's nl2br() function? :P
RE: PHP textarea help by -dt- on 11-19-2005 at 04:18 PM

quote:
Originally posted by Leo
quote:
Originally posted by -dt-
do something like
code:
$message = $_POST['textarea'];
$message = str_replace("\n",'
',$message);


and it should turn all newlines into
's
Why not use PHP's nl2br() function? [Image: msn_tongue.gif]
:-/ because as it says "Inserts HTML line breaks before all newlines in a string" , keeping the new lines is just blah replacing them is alot better :P
RE: PHP textarea help by L. Coyote on 11-19-2005 at 05:48 PM

If you view the source code, keeping \n can be useful. *-)

But meh, whatever.

Btw, are you using your editor? Because it took the <br>'s in the quoted post...


RE: PHP textarea help by Ezra on 11-19-2005 at 08:36 PM

thnx :), I used -dt-'s code, so I can change them back If I want to put it into a textarea again :)


RE: PHP textarea help by -dt- on 11-20-2005 at 01:16 AM

quote:
Originally posted by Leo
If you view the source code, keeping \n can be useful. *-)

But meh, whatever.

Btw, are you using your editor? Because it took the <br>'s in the quoted post...
oh thats odd....*looks at quoting code* ah :-/ i wasnt escaping the html....
and tis fixed and uploaded...