我的问题是现在需要使用正则表达式匹配名为iframe的html标签,但是并非所有的标签都要匹配,在匹配时不要匹配src属性包含"swf"字符串的标签,例如我有html标签:
<iframe src="http:/www.google.com/"></iframe>
<iframe src="http:/www.google.com/2.html"></iframe>
<iframe src="http:/www.google.com/1.swf"></iframe>如何通过正则表达式找出:
<iframe src="http:/www.google.com/"></iframe>
<iframe src="http:/www.google.com/2.html"></iframe>
但是不要匹配:
<iframe src="http:/www.google.com/1.swf"></iframe>非常感谢!
<iframe src="http:/www.google.com/"></iframe>
<iframe src="http:/www.google.com/2.html"></iframe>
<iframe src="http:/www.google.com/1.swf"></iframe>如何通过正则表达式找出:
<iframe src="http:/www.google.com/"></iframe>
<iframe src="http:/www.google.com/2.html"></iframe>
但是不要匹配:
<iframe src="http:/www.google.com/1.swf"></iframe>非常感谢!
$html = <<<HTML
<iframe src="http:/www.google.com/"></iframe>
<iframe src="http:/www.google.com/2.html"></iframe>
<iframe src="http:/www.google.com/1.swf"></iframe>
HTML;
$reg = '/<iframe[^>]*?src="[^"]*?\.(?!swf)[^\."]*"[^>]*><\/iframe>/i';preg_match_all($reg, $html, $matches);
var_dump($matches);