如何匹配< iframe>的一部分标签? [英] How to match a part of an <iframe> tag?
本文介绍了如何匹配< iframe>的一部分标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想匹配这个字符串中突出显示的部分:
I'm trying to match the highlighted parts of this string:
<iframe maybe something here src="http://some.random.url.com/" and the string continues...
如果它放置在标签内,我需要匹配src =。 iframe标记可以放在源代码中的任何位置。
I need to match the src="" if it's placed inside of an tag. The iframe tag can be placed anywhere in the source.
预先感谢! :)
推荐答案
您应该为此使用DOM解析器。这里有一个DOMDocument的例子:
You should use a DOM parser for that. Here's an example with DOMDocument :
<?php
$document = new DOMDocument();
$document->loadHTML(file_get_contents('yourFileNameHere.html'));
$lst = $document->getElementsByTagName('iframe');
for ($i=0; $i<$lst->length; $i++) {
$iframe= $lst->item($i);
echo $iframe->attributes->getNamedItem('src')->value, '<br />';
}
?>
这篇关于如何匹配< iframe>的一部分标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文