Retaining carriage returns in textarea boxes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
voltrader
Forum Contributor
Posts: 223
Joined: Wed Jul 07, 2004 12:44 pm
Location: SF Bay Area

Retaining carriage returns in textarea boxes

Post by voltrader »

How do I correctly format for carriage returns input into textarea boxes?

For example, if a user entered two lines separated by pressing the "enter" key, the text is POSTed without the line feeds.

How do I retain the line feeds?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

The carriage returns are there, just that when you output the text in html they're ignored (HTML ignores whitespace). Use nl2br() to convert them into <br /> tags.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Wow I didn't know such a function existed!!! I've been writing functions to convert certain features to html for the past year. Grrrr :roll: :twisted:
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

That is why i love this forum :)

Discover new functions (or situations where a function comes in handy) every day.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

If you visit the php.net website function definition for nl2br() and check the comments there is a link to a beefed up version of nl2br().

I believe it is at this web address. It is a pretty good function that I have used in several applications.
Post Reply