如何用PHP格式从textarea中读取换行符?

如何用PHP格式从textarea中读取换行符?

问题描述:

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 wrote it?

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

Thanks

如何阅读换行符,以便用户填写表单内的文本区域,然后 点击提交,文本的显示方式与它们写的完全相同吗? p>

我应该提一下我在php文件中用POST方法读取表单中的变量。 p>

谢谢 p> div>

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

If you want to reproduce the newlines of your users input in HTML, you have to convert every 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
 bar"); ?>

The above example will output:

foo isn't<br /> bar