3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dom = new DOMDocument; $file = <<<DATA <body> <div class="test"> <p> <img src="loading.gif" data-src="https://test.com/images/images/120/1313131313232.jpg" alt="test" /> </p> <img src="loading.gif" data-src="https://test.com/images/images/120/1313131313232.jpg" alt="test" /> </div> <div class="test"> This is text <img src="loading.gif" data-src="https://test.com/images/images/120/1313131313232.jpg" alt="test" /> </div> <div> <img src="loading.gif" data-src="https://test.com/images/images/120/1313131313232.jpg" alt="test" /> </div> </body> DATA; @$dom->loadHTML($file); $xpath = new DOMXPath($dom); $divs = $xpath->query('//div[@class="test"]'); foreach ($divs as $key => $div) { echo $div->textContent . PHP_EOL; foreach ($div->getElementsByTagName("img") as $img) { if ($img->getAttribute('alt') === 'test') { echo $img->getAttribute('data-src') . PHP_EOL; } } }
Output for git.master, git.master_jit, rfc.property-hooks
https://test.com/images/images/120/1313131313232.jpg https://test.com/images/images/120/1313131313232.jpg This is text https://test.com/images/images/120/1313131313232.jpg

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