Is there a function like “getAllChildrenByTagName” in PHP?
$dom = new DOMDocument();
$dom->loadXML('<p><a id="1">test 1</a><span><a id="2">test 2</a></span></p>');
foreach($dom->getElementsByTagName('a') AS $node)
echo($node->textContent);
Here i only want the a-Tag with “id = 1”. Is it possible?
You can to use XPath to directly grab the element you’re looking for:
This will print: