dom - PHP DOMXPath Query -


i trying read href , img inside tag using php domxpath query.

i using below "a" tag

$showpage = file_get_contents($url);    $dom = new domdocument(); $dom->validateonparse = true; $dom->loadhtml($showpage);   $dom->preservewhitespace = false;             $allbollylist = new domxpath($dom); $allbollytablehtml = $allbollylist->query('//div[contains(@class, "covers")]//a');   foreach($allbollytablehtml $item) {      $sourcelink = $item->getattribute("href");       }  

however, "a" in html below.

<a href="http://test.com/songs"><img src="http://test.com/test.jpg" alt="song name"><div></div></a> 

i want read "img" tag , read "src" , "alt" inside "img" tag.

can please trying in php new?

thanks

never mind. found below solution read "img" tag inside of "a" tag.

    foreach($item->getelementsbytagname('img') $img){         echo $img->getattribute('src') . "\r\n";     } 

so new loop read "allbollytablehtml" below.

foreach($allbollytablehtml $item) {      $sourcelink = $item->getattribute("href");            foreach($item->getelementsbytagname('img') $img){         echo $img->getattribute('src');     } }  

Comments