如何匹配<iframe>标签的一部分?

qwe*_*rty 2 html php regex match

我正在尝试匹配此字符串的突出显示部分:

<iframe maybe something here src="http://some.random.url.com/" and the string continues...

我需要匹配src ="",如果它放在标签内.iframe标记可以放在源代码中的任何位置.

提前致谢!:)

HoL*_*ieR 14

您应该使用DOM解析器.这是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 />';
    }
?>
Run Code Online (Sandbox Code Playgroud)

  • @Nick只考虑这个例子:<! - <iframe src =" - ></iframe> NotAPath"> regexp如何有效识别它不是iframe? (3认同)