Hi, I was just wondering if there is an easy method of preserving line breaks from a submitted form. So like, I have a textarea in a form, and I need to keep the line breaks the user enters, and store what the user entered in a MySQL table. I was thinking about \n but I'm not too sure that'll work at all. Thanks!
Ah, I forgot to mention, I need to redisplay this data with the entered line breaks.
__________________
I'm not always the most helpful, but I'm trying :P
Please don't post incorrect answers when the original question has already been answered.
LOL - don't post incorrect answers at any time!
__________________
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Quote:
Will nl2br() make the <br /> tags show up inside the textarea, or do they actually show up as a line break?
You shouldn't use nl2br() if you are echoing the value within <textarea> tags-- any text within those tags will show up in the input box automatically wrapping each line to fit inside the box (just as it wraps lines are you are typing into a box).
So that was a long answer to your question-- short answer, Yes, you will see the <br /> within the textbox if you use nl2br() in that instance.
nl2br() is handy when displaying the text normally (within <p> tags for example).