3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); $htmlString = <<<_HTML <div> <a href="A"><img src="X"></a> <a href="C"><img src="X"></a> <a href="D"><img src="X"></a> <a href="E"><img src="X"></a> <a href="F"><img src="X"></a> <p> <a href="G"><img src="X"></a> </p> <a href="H">No image in this one</a> </div> _HTML; $doc = new DOMDocument(); $doc->loadHTML($htmlString, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($doc); $links = $xpath->query('//a[@href and img]'); foreach ($links as $link) { $link->setAttribute('href', 'B'); } $newHtmlString = $doc->saveHTML(); echo $newHtmlString;
Output for 7.1.0 - 7.1.33, 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.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.27, 8.3.29 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
<div> <a href="B"><img src="X"></a> <a href="B"><img src="X"></a> <a href="B"><img src="X"></a> <a href="B"><img src="X"></a> <a href="B"><img src="X"></a> <p> <a href="B"><img src="X"></a> </p> <a href="H">No image in this one</a> </div>
Output for 8.3.28
/bin/php-8.3.28: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.3.28)
Process exited with code 1.

preferences:
189.5 ms | 408 KiB | 5 Q