Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-13-2007, 08:56 AM   PM User | #1
lobsterninja
New Coder

 
Join Date: Jul 2005
Location: Northfield, MA
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
lobsterninja is an unknown quantity at this point
Preserving Line Breaks

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
lobsterninja is offline   Reply With Quote
Old 03-13-2007, 10:43 AM   PM User | #2
ess
Regular Coder

 
Join Date: Oct 2006
Location: United Kingdom
Posts: 865
Thanks: 7
Thanked 29 Times in 28 Posts
ess will become famous soon enough
Store the data from the textarea as it is, and when outputting data to the browser, use the following function

nl2br

cheers,
Ess
ess is offline   Reply With Quote
Old 03-13-2007, 03:56 PM   PM User | #3
the-dream
Regular Coder

 
the-dream's Avatar
 
Join Date: Mar 2007
Location: Northamptonshire, UK
Posts: 477
Thanks: 8
Thanked 4 Times in 4 Posts
the-dream can only hope to improve
if you use

PHP Code:
$_POST['blah']; 
it should work!

Like

PHP Code:
<?php
$field 
$_POST['blah'];
echo = 
$field;
?>
__________________
Branchr Advertising Network
the-dream is offline   Reply With Quote
Old 03-13-2007, 06:07 PM   PM User | #4
aedrin
Senior Coder

 
Join Date: Jan 2007
Posts: 1,648
Thanks: 1
Thanked 58 Times in 54 Posts
aedrin will become famous soon enough
Please don't post incorrect answers when the original question has already been answered.
aedrin is offline   Reply With Quote
Old 03-13-2007, 08:11 PM   PM User | #5
lobsterninja
New Coder

 
Join Date: Jul 2005
Location: Northfield, MA
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
lobsterninja is an unknown quantity at this point
Quote:
Originally Posted by ess View Post
Store the data from the textarea as it is, and when outputting data to the browser, use the following function

nl2br

cheers,
Ess
Wow, thanks, it works perfectly
__________________
I'm not always the most helpful, but I'm trying :P
lobsterninja is offline   Reply With Quote
Old 03-13-2007, 09:52 PM   PM User | #6
JohnDubya
Super Moderator


 
JohnDubya's Avatar
 
Join Date: Nov 2006
Location: Missouri
Posts: 634
Thanks: 12
Thanked 18 Times in 18 Posts
JohnDubya is on a distinguished road
Will nl2br() make the <br /> tags show up inside the textarea, or do they actually show up as a line break?
__________________
JDub
http://johnnyzone.com/blog
JohnDubya is offline   Reply With Quote
Old 03-13-2007, 10:00 PM   PM User | #7
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,712
Thanks: 2
Thanked 251 Times in 243 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
Quote:
Originally Posted by aedrin View Post
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.
CFMaBiSmAd is online now   Reply With Quote
Old 03-13-2007, 10:12 PM   PM User | #8
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
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).
__________________
Fumigator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:30 PM.


Advertisement
Log in to turn off these ads.