2017-01-16 57 views
0

(有將在HTML其他I幀,所以我想通過類名來稱呼他們)獲得的getAttribute SRC由getElementsByClassName方法不工作PHP的DOMDocument

我想:

$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; 
+0

有人嗎?嘗試了很多東西 – newuser0250

回答

0

使用下面的嘗試代碼:

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

什麼都沒有返回,但謝謝 – newuser0250