PHP DOMXPATH & Array

Sarah

New Member
I'm trying to extract all relevant URLs and images out of a page and put them into an array, the code below works fine except it outputs the first pair over and over for the numerically-correct number of times. I thought maybe I was making mistakes when specifying XPATHs but I've tested it on 3 different sites with the same result every time.\[code\]$dom = new DOMDocument();$dom->loadHtml( $html );$xpath = new DOMXPath( $dom );$items = $xpath->query( "//div[@class=\"row\"]" );foreach ( $items as $item ) {$value['url'] = $xpath->query( "//div[@class=\"productImg\"]/a/@href",$item)->item(0)->nodeValue;$value['img'] = $xpath->query("//div[@class=\"productImg\"]/a/img/@src",$item)->item(0)->nodeValue;$result[] = $value;}print_r($result);\[/code\]Clearly the code isn't right but I haven't been able to narrow it down to the offending portion. And before somebody suggests using regex that is something I'd usually do but I'd prefer to use XPATH now if possible.
 
Back
Top