3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <div class="pd_warranty col-xs-12 no-padding"> <p class="selectWty txtLeft">Available Options</p> <div class="vspace clear"></div> <div class="subProd col-xs-4 noPadLR"> <a href="https://www.example.com/single” class="selected"> <div class="col-xs-12 cellTable pad5All"> <div class="col-xs-8 noPadLR cellTableCell"> <p class="noMar txtLeft">Single</p> <p class="noMar txtLeft sml">$99.99</p> </div> </div> </a> </div> <div class="subProd col-xs-4 noPadLR"> <a href="https://www.example.com/2pack” class=""> <div class="col-xs-12 cellTable pad5All"> <div class="col-xs-8 noPadLR cellTableCell"> <p class="noMar txtLeft">2-PACK</p> <p class="noMar txtLeft sml">$159.99</p> </div> </div> </a> </div> <div class="subProd col-xs-4 noPadLR"> <a href="https://www.example.com/4pack” class=""> <div class="col-xs-12 cellTable pad5All"> <div class="col-xs-8 noPadLR cellTableCell"> <p class="noMar txtLeft">4-PACK</p> <p class="noMar txtLeft sml">$249.99</p> </div> </div> </a> </div> </div> HTML; $dom = new DOMDocument; $dom->loadHTML(str_replace ('”', '"', $html)); // normalize the quoting; extend as needed $xpath = new DOMXPath($dom); // actually targeting this div ---------vvv foreach ($xpath->evaluate("//div[contains(@class, 'subProd')]//div[contains(p/@class, 'noMar')]") as $div) { $type = $xpath->query("p[contains(@class, 'noMar') and not(contains(@class, 'sml'))]", $div)[0]->nodeValue; $price = $xpath->query("p[contains(@class, 'noMar') and contains(@class, 'sml')]", $div)[0]->nodeValue; $result[$type] = $price; } var_export($result);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 'Single' => '$99.99', '2-PACK' => '$159.99', '4-PACK' => '$249.99', )

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:
127.66 ms | 405 KiB | 5 Q