joe joe - 7 months ago 52
PHP Question

Getting into child nodes with php DOMDocument

I know this has been asked a few times before but I really can't seem to figure it out from other examples on here.

$classname = "gallery2";
$pageDOM = new DOMDocument();

$xpath = new DOMXPath($pageDOM);
$ul = $xpath->query("//ul[@class='$classname']");
$ulNode = $ul->item(0);

$ulHTML = new DOMDocument();

$ulHTML->appendChild($ulHTML->importNode($ulNode, TRUE));
$ulHTMLsaved = $ulHTML->saveHTML();

on $ulHTMLsaved returns all the markup that I want, but then how do I do a foreach and get into to a child node from the existing variable that I've set?

contains something like the following & I want to grab various attributes from other nodes nested within all the

<img src="img.jpg" alt="">
<a href="">
<img src="img.jpg" alt="">

joe joe

You can get into child elements by searching for them with the following:



There will probably be a more generic one too for classes similar to javascript's querySelectorAll, but not sure what that is currently.