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"; }
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
IMG#0: src = /image/fluffybunny.jpg title = Harvey the bunny alt = a cute little fluffy bunny --- IMG#1: src = /image/pricklycactus.jpg title = Roger the cactus alt = a big green prickly cactus --- IMG#2: src = /image/noisycockatoo.jpg title = Polly the cockatoo alt = an annoying white cockatoo --- IMG#3: src = somethingelse title = something alt = ---

preferences:
183.39 ms | 404 KiB | 225 Q