php - javascript replace newlines in textareas
566
I have atextarea
in a contact form, when it is submitted to the page that sends the mail, it passes through another page.
in the second page, when Iecho $_POST['textarea']
I get all the text in one line.
Is there a javascript or PHP code that fix this?
Answer
Solution:
Have a look at PHP's
.
Example #1 from the above link:
Answer
Solution:
Assuming your output page is HTML, you need to convert the lines to
<br/>
tags.Example:
This is because HTML treats all whitespace the same (That is: any amount of whitespace is just 1 space). (If you view the source of your page, which is usually rendered as plain text, you'll see the line breaks)
Answer
Solution:
If you are echoing it not into a new textarea, the new lines will be compressed out by the browser in the HTML. You can use nl2br() to fix that.
Answer
Solution:
Here's some JavaScript code that will do this as well: JavaScript nl2br