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);

preferences:
24.69 ms | 404 KiB | 5 Q