通过getElementsByClassName从iframe获取getAttribute src不能正常运行php domdocument

时间:2017-01-16 12:34:07

标签: php iframe domdocument getelementsbyclassname

(html中会有其他iframe,所以我试图通过类名调用它们)

我试过了:

$html = "<iframe width='100%' height='600' class='report' id='CReport' src='  http://www.example.com' ></iframe>";

$doc = new DOMDocument();
@$doc->loadHTML($html);

$tags = $doc->getElementsByClassName('report');
$url = $tags->getAttribute('src');
echo $url;

1 个答案:

答案 0 :(得分:0)

尝试使用以下代码:

<?php $tags = $doc->getElementById('CReport'); ?>