PHP, strip_tags stripping \n in text area. How to stop it?

喜欢而已 提交于 2019-12-04 03:33:13

问题


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?

Thanks!!!


回答1:


You can use nl2br to add the BR line break element to line break character sequences:

$html = nl2br($plain);

Note that the BR elements are just added:

nl2br("foo\nbar") === "foo\n<br />bar"

And to prevent strip_tags to remove P and BR tags, specify them in the second parameter:

$clean = strip_tags($html, '<p><br>');


来源:https://stackoverflow.com/questions/5069916/php-strip-tags-stripping-n-in-text-area-how-to-stop-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!