PHP,strip_tags 在文本区域中剥离 \n.如何阻止它? [英] PHP, strip_tags stripping \n in text area. How to stop it?
本文介绍了PHP,strip_tags 在文本区域中剥离 \n.如何阻止它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望能够接受 \n
或 \r\n
并将它们转换为 <br/>
在页面中使用.尽管当用户提交带有新段落的文本区域时,strip_tags
函数似乎会将它们直接删除.我可以做些什么来将这些保留在字符串中?
I would like to be able to accept \n
or \r\n
and convert them to <br />
for use in the page. Although when a user submits a text area with new paragraphs, the strip_tags
function seems to strip them right out. Anything I can do to keep these in the string?
谢谢!!!
推荐答案
您可以使用 nl2br
将 BR
换行元素添加到换行符序列:
You can use nl2br
to add the BR
line break element to line break character sequences:
$html = nl2br($plain);
注意 BR
元素是刚刚添加的:
Note that the BR
elements are just added:
nl2br("foo\nbar") === "foo\n<br />bar"
并防止 strip_tags
删除 P
和BR
标签,在第二个参数中指定:
And to prevent strip_tags
to remove P
and BR
tags, specify them in the second parameter:
$clean = strip_tags($html, '<p><br>');
这篇关于PHP,strip_tags 在文本区域中剥离 \n.如何阻止它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文