开发者

HTML textarea newline character

I have a text area in HTML where the user can enter text, but when the form is submitted, and its passed to a php script which echo's it, there aren't any newlines. Knowing that HTML does that, I tried doing a preg_replace() before echoing it...

    echo preg_replace("/\n/", "<br />", $_GET["text"]);

but still everything is on one line.

So my best guess is that HTML textareas use a different newline character... can anybody shed some light on the subject?

EDIT

Ok, so I've figured out开发者_高级运维 the problem: The Javascript is stripping the newlines. view code here

EDIT 2

Ok, so thanks to Jason for solving this problem. I needed to do:

    escape(document.getElementById('text'));

Instead of just:

    document.getElementById('text');

and the newlines are preserved, problem solved!


echo nl2br($_GET['text'])

Though, your preg_replace worked for me!


usually when testing for newlines in any string, I use /[\n\r]/, just to cover my bases. My guess is that this would match the new lines.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜