php - javascript replace newlines in textareas


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?




Assuming your output page is HTML, you need to convert the lines to<br/> tags.


echo nl2br($_POST['textarea']);

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)




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.

People are also looking for solutions to the problem: search - PHP - How do I cut out a block of lines in a text document?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.