3v4l.org

run code in 300+ PHP versions simultaneously
<?php $test = <<<HTML <img src="/image/fluffybunny.jpg" title="Harvey the bunny" alt="a cute little fluffy bunny" /> <img src='/image/pricklycactus.jpg' title='Roger the cactus' alt='a big green prickly cactus' /> <p>This is irrelevant text.</p> <img alt="an annoying white cockatoo" title="Polly the cockatoo" src="/image/noisycockatoo.jpg"> <img title=something src=somethingelse> HTML; libxml_use_internal_errors(true); // silences/forgives complaints from the parser (remove to see what is generated) $dom = new DOMDocument(); $dom->loadHTML($test); foreach ($dom->getElementsByTagName('img') as $i => $img) { echo "IMG#{$i}:\n"; echo "\tsrc = " , $img->getAttribute('src') , "\n"; echo "\ttitle = " , $img->getAttribute('title') , "\n"; echo "\talt = " , $img->getAttribute('alt') , "\n"; echo "---\n"; }

preferences:
50.98 ms | 402 KiB | 5 Q