3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<'HTML' <div class="blockImg imgRight"> <img src="customs/2/pictures/home.png"> <figcaption>Une légende</figcaption> </div> HTML; // on ajoute la structure manquante pour préciser l'encodage $html = <<<HTML <html><head><meta charset="utf-8"/></head><body>$html</body></html> HTML; $dom = new \DOMDocument; $dom->loadHTML($html, LIBXML_NOERROR); $context = $dom->getElementsByTagName('div')[0]; $xp = new \DOMXPath($dom); // on extrait la valeur de l'attribut class tout en vérifiant la présence de la classe "blockImg" $classAttrValue = $xp->evaluate( 'string(@class[contains(concat(" ", normalize-space(.), " "), " blockImg ")])', $context ); if ($classAttrValue && preg_match('~ \b img (?: Right | Left ) \b ~x', $classAttrValue, $m)) { $class = $m[0]; $src = $xp->evaluate('string(img/@src)', $context); $filename = basename($src); $caption = $xp->evaluate('string(figcaption)', $context); echo $class, PHP_EOL, $src, PHP_EOL, $filename, PHP_EOL, $caption, PHP_EOL; }
Output for 8.1.32 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.14, 8.4.16 - 8.4.18, 8.5.0 - 8.5.3
imgRight customs/2/pictures/home.png home.png Une légende
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
72.63 ms | 407 KiB | 5 Q