开发者

how to read new-line from a textarea in a form with PHP?

How can I read the New-line so that when users fill in a text-area inside my form, and then hit submit, the text is displayed exactly the same way as they 开发者_JAVA百科wrote it?

I should mention I read in the variables from the form with POST method in my php file.

Thanks


The newline character in PHP is presented by the string "\n".

If you want to reproduce the newlines of your users input in HTML, you have to convert every \n to a <br />. You could do that by hand or use the function nl2br in such a way:

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


Take a look at the nl2br function.

Example from documentation:

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

The above example will output:

foo isn't<br /> bar

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜