使用带有html标签的nl2br [英] Using nl2br with html tags
本文介绍了使用带有html标签的nl2br的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 nl2br
来显示一些保存在某处的信息,但是当使用HTML标记时,我不想添加< br>
标签。
例如,如果我使用
<表>
< th>< / th>
< / table>
它将被转换为
< table>< br />
< th>< / th>< br />
< / table>< br />
,这为此表格创造了很多空间。
何可以为其他非HTML内容添加分行标签?
谢谢。
$> str = str_replace('>
','>',$ str);
I use nl2br
when displaying some information that is saved somewhere, but when HTML tags are used I want not to add <br>
tags for them.
For example if I use
<table>
<th></th>
</table>
it will be transformed to
<table><br />
<th></th><br />
</table><br />
and that makes a lot of spaces for this table.
Ho can break line tags be added only for other non-HTML content?
Thanks.
解决方案
You could replace the closing tags and newlines by only closing tags:
$str = str_replace('>
', '>', $str);
这篇关于使用带有html标签的nl2br的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文