开发者

Regular expression to match tags containing certain data

I need help to make a reg exp. to match these: The goal is to match any html tag that only <br/> or/and spaces.

<p><br/></p>
<h1><br/></h1>
<p><br/><br/></p>
<span><br/><br/></span>
<b><br/>   <br/>    </b>
<h2><br/>   <br/>    </h2>
开发者_StackOverflow中文版


Try:

preg_match_all('#<([\S]+)[^>]*>(\s*|(<br\s*/>)*)*</\\1>#i', $html, $m);

If you want to strip elements that contain only comments as well as whitespace/<br/>, that's going to be a pain, maybe even impossible, using regex alone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜