开发者

javascript replace newlines in textareas

I have a textarea in a contact form, when it is submitted to the page that se开发者_运维百科nds the mail, it passes through another page.

in the second page, when I echo $_POST['textarea'] I get all the text in one line.

Is there a javascript or PHP code that fix this?


Have a look at PHP's nl2br.

Example #1 from the above link:

<?php
echo nl2br("foo isn't\n bar");
?>


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

Example:

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.


Here's some JavaScript code that will do this as well: JavaScript nl2br

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜