3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = <<<HTML This is some sample data which is going to contain an image in the format <img src="http://www.randomdomain.com/randomfolder/randomimagename.jpg">. It will also contain lots of other text and maybe another image or two like this: <img alt='another image' src='http://www.example.com/randomfolder/randomimagename.jpg'> HTML; $srcs = []; $dom=new DOMDocument; $dom->loadHTML($string); foreach ($dom->getElementsByTagName('img') as $img) { $srcs[] = $img->getAttribute('src'); } var_export($srcs);
Output for 5.6.38, 7.1.0 - 7.1.25, 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.25, 8.4.1 - 8.4.12
array ( 0 => 'http://www.randomdomain.com/randomfolder/randomimagename.jpg', 1 => 'http://www.example.com/randomfolder/randomimagename.jpg', )

preferences:
117.26 ms | 408 KiB | 5 Q