...

View Full Version : Preserving Line Breaks



lobsterninja
03-13-2007, 08:56 AM
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.

ess
03-13-2007, 10:43 AM
Store the data from the textarea as it is, and when outputting data to the browser, use the following function

nl2br (http://php.net/nl2br)

cheers,
Ess

the-dream
03-13-2007, 03:56 PM
if you use


$_POST['blah'];

it should work!

Like



<?php
$field = $_POST['blah'];
echo = $field;
?>

aedrin
03-13-2007, 06:07 PM
Please don't post incorrect answers when the original question has already been answered.

lobsterninja
03-13-2007, 08:11 PM
Store the data from the textarea as it is, and when outputting data to the browser, use the following function

nl2br (http://php.net/nl2br)

cheers,
Ess

Wow, thanks, it works perfectly :)

JohnDubya
03-13-2007, 09:52 PM
Will nl2br() make the <br /> tags show up inside the textarea, or do they actually show up as a line break?

CFMaBiSmAd
03-13-2007, 10:00 PM
Please don't post incorrect answers when the original question has already been answered.LOL - don't post incorrect answers at any time! :D

Fumigator
03-13-2007, 10:12 PM
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).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum