What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » PHP textarea help

PHP textarea help
Author: Message:
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
O.P. PHP textarea help
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
[Image: 1-0.png]
             
11-19-2005 03:43 PM
Profile PM Web Find Quote Report
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
36 / Male / Flag
Joined: Mar 2004
RE: PHP textarea help
do something like
code:
$message = $_POST['textarea'];
$message = str_replace("\n",'<br>',$message);


and it should turn all newlines into <br>'s
[Image: dt2.0v2.png]      Happy Birthday, WDZ
11-19-2005 03:57 PM
Profile PM Web Find Quote Report
L. Coyote
Senior Member
****

Avatar
Captain Obvious

Posts: 981
Reputation: 49
39 / Male / Flag
Joined: Aug 2004
Status: Away
RE: PHP textarea help
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

Hack, hack, hack!
Finally became a Systems Analyst! :spam:

11-19-2005 04:04 PM
Profile PM Find Quote Report
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
36 / Male / Flag
Joined: Mar 2004
RE: PHP textarea help
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
[Image: dt2.0v2.png]      Happy Birthday, WDZ
11-19-2005 04:18 PM
Profile PM Web Find Quote Report
L. Coyote
Senior Member
****

Avatar
Captain Obvious

Posts: 981
Reputation: 49
39 / Male / Flag
Joined: Aug 2004
Status: Away
RE: PHP textarea help
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...

Hack, hack, hack!
Finally became a Systems Analyst! :spam:

11-19-2005 05:48 PM
Profile PM Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
O.P. RE: PHP textarea help
thnx :), I used -dt-'s code, so I can change them back If I want to put it into a textarea again :)
[Image: 1-0.png]
             
11-19-2005 08:36 PM
Profile PM Web Find Quote Report
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
36 / Male / Flag
Joined: Mar 2004
RE: PHP textarea help
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...
[Image: dt2.0v2.png]      Happy Birthday, WDZ
11-20-2005 01:16 AM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On