3v4l.org

run code in 300+ PHP versions simultaneously
<?php $res = ' <html> <div class="product bla bla"> <div class="size">xxl</div> <div class="color yy">red</div> </div> <div class="product bla"> <div class="size xxs">xxs</div> <div class="line line2">new</div> </div> <div class="product asd"> <div class="color xx">blue</div> </div> </html> '; $dom = new DomDocument(); @ $dom->loadHTML($res); // utf8_decode $dom->preserveWhiteSpace = false; // ? $xpath = new DomXPath($dom); $nodes = $xpath ->query("//*[contains(@class, 'product')]"); echo "Found {$nodes->length} matching places" . PHP_EOL; foreach($nodes as $node){ $name = $xpath->query("*[contains(@class, 'color')]", $node); echo null === $name[0] ? 'NULL' : $name[0]->nodeValue; echo PHP_EOL; }
Output for git.master, git.master_jit, rfc.property-hooks
Found 3 matching places red NULL blue

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
40.73 ms | 405 KiB | 5 Q