3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = '<div class="classA"> <a id="someID1"></a> <div class="class1"> <div class="class2"> <div class="class3"> <div class="class4"> <h4>name, name<small>string</small></h4> </div> <div> <h4>number<small>string</small></h4> </div> </div> </div> </div> </div> <div class="classA"> <a id="someID2"></a> <div class="class1"> <div class="class2"> <div class="class3"> <div class="class4"> <h4>nameA,nameA<small>stringA</small></h4> </div> <div> <h4>numberA<small>stringB</small></h4> </div> </div> </div> </div> </div>'; $doc = new DOMDocument(); $doc->loadHTML($html); $xpath = new DOMXpath($doc); $nodes = $xpath->query("//div[@class='classA' and a[@id='someID2']]")->item(0)->getElementsByTagName("h4"); echo $nodes->item(0)->nodeValue;
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
nameA,nameAstringA

preferences:
89.72 ms | 407 KiB | 5 Q