从html中删除特定的标签

时间:2013-04-17 14:13:58

标签: php html-parsing

我正在解析我网站上的各种html页面。我想删除一些特定的'a'标签。 所有标签都是这样的:

<a href="#cite-note-2"><span>..</span></a>
<a href="#cite-sub">....</a>

所以我想要的是删除href以#cite

开头的所有标签

请在php中建议一些regEx。感谢

1 个答案:

答案 0 :(得分:0)

试试这个正则表达式:

'/<a[\s]{1,}href=[\'"]\#cite.*?[\'"].*?>.*?<\/a>/ims'

例如:

$a = preg_replace('/<a[\s]{1,}href=[\'"]\#cite.*?[\'"].*?>.*?<\/a>/ims', '', $a);