我正在使用文本区域使用户能够输入评论。但是,如果用户输入新行,则新行在输出时不会出现。有什么办法可以使换行符停留。
知道如何保存换行符吗?
最佳答案
两种解决方案:
PHP函数nl2br()
:
例如。,
echo nl2br("This\r\nis\n\ra\nstring\r");
// will output
This<br />
is<br />
a<br />
string<br />
将输入内容包装在
<pre></pre>
标记中。参见:W3C Wiki - HTML/Elements/pre
关于php - 写入MySQL时保留TextArea的换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59011914/