Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

POSTing textarea data with line breaks

Status
Not open for further replies.

djtizzlemaster

Programmer
Mar 5, 2008
17
0
0
US
Working on an order form. On the page with the form (let's say form.php), there are textareas.

Let's say a user enters this data into a textarea:
Line 1
Line 2
Line 3

On the page that this form is POSTed to (let's say verify.php), when I echo the variable, it shows up as:
Line 1 Line 2 Line 3

Notice there are still spaces in between Line1 and Line 2, and between Line 2 and Line 3. This seems to indicate that verify.php is reading those line breaks but instead turning them into spaces.

How do I get it to display exactly as it was on form.php?
Line 1
Line 2
Line 3
 
By the way, I know the first potential solution that probably comes to mind is to add wrap="physical" to the textarea tag, so I just wanted to clarify that I've already done this, and that doesn't fix the problem!
 
Exactly how are you echoing the text back? into another text area, or just as standard text onto the page?

I would be willing to bet that if you echo into another textarea the line brakes are preserved, but because html doesn't recognize line breaks you'll need to take the text, and change all the line ending characters like \r\n\ to <br> tags.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
On your posted page, use this. See if the breaks are actually there.
Code:
<?php
echo '<pre>';print_r($_POST);echo "</pre>";die;
?>


You could also replace the carriage returns with line breaks.
Code:
$field = urlencode($field);
$field = str_replace("%0D","<br>",$field);
$field = urldecode($field);

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top