0
我想抓住一個HTML內的img標籤。該HTML看起來有點像這樣:PHP的DOMDocument:getElementsbyTagName('IMG')不工作
<img style='width:198px;height:279px;' class='featureImg' src='image-loader.gif' data-src='http://somesites.com/med/1455.jpg' alt="Picture">
現在我要搶IMG SRC http://somesites.com/med/1455.jpg
。
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($html);
$divs = $dom->getElementsByTagName('img');
foreach ($divs as $div){
if(preg_match_all('/\bfeatureImg\b/', $div->getAttribute('class'))) {
$links = $div->getElementsByTagName('img');
foreach($links as $link){
$li = $link->getAttribute('data-src');
echo ($li.'<br>');
}}}
並沒有工作...任何人的幫助?
不應該是'$ link-> getAttribute('src');'? – andre3wap