【发布时间】:2015-09-01 03:31:14
【问题描述】:
需要一个用于 preg_replace 的正则表达式。
“另一个问题”中没有回答此问题,因为并非我要删除的所有标签都不为空。
我不仅要从 HTML 结构中删除空标签,还要删除包含换行符、空格和/或其 html 代码的标签。
可能的代码是:
在删除匹配标签之前:
<div>
<h1>This is a html structure.</h1>
<p>This is not empty.</p>
<p></p>
<p><br /></p>
<p> <br /> &;thinsp;</p>
<p> </p>
<p> </p>
</div>
删除匹配标签后:
<div>
<h1>This is a html structure.</h1>
<p>This is not empty.</p>
</div>
【问题讨论】:
标签: php html regex preg-replace