3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = <<<DATA <p>a lot of some html code here</p> <p class="price"> <strong>2680 $</strong> <div>a lot of some random html code here</div> <p class="price"> <strong>3250 $</strong> <p>a lot of some good html code here</p> <p class="price"> <strong>3450 $</strong> <div id="promoted-after"></div> <p class="price"> <strong>400 $</strong> <td>a lot of some strange html code here</td> <p class="price"> <strong>401 $</strong> <div>a lot of some awesome html code here</div> <p class="price"> <strong>402 $</strong> <span>a lot of some ugly html code here</span> <p class="price"> <strong>403 $</strong> <div>a lot of some nice html code here</div> <p class="price"> <strong>404 $</strong> <table>a lot of some best html code here</table> DATA; $dom = new DOMDocument(); $dom->loadHTML($data); $xpath = new DOMXPath($dom); $items = $xpath->query('//div[@id="promoted-after"]/following-sibling::p/strong'); foreach($items as $item) { echo $item->nodeValue . PHP_EOL; }
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.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
400 $ 401 $ 402 $ 403 $ 404 $

preferences:
139.52 ms | 408 KiB | 5 Q