3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <body> <img src="http://example/img/product/name/thumbs/100/img.jpg" alt="lol" width="100" height="100" caption="false" class="popup-img left" /> </body> HTML; $dom = new DOMDocument(); $dom->loadHTML($html); $xpath = new DOMXPath($dom); $nodes = $xpath->query('//img[contains(@class, "popup-img")]'); foreach($nodes as $node) { $a = $dom->createElement('a'); $a->setAttribute('class', $node->getAttribute("class")); $a->setAttribute('title', $node->getAttribute("alt")); $href = parse_url($node->getAttribute("src"), PHP_URL_PATH); $a->setAttribute('href', '..' . str_replace('/thumbs/100/', '/', $href)); $a->setAttribute('style', "background: url('..$href'); -webkit-background-size:cover; background-size:cover;"); $node->parentNode->insertBefore($a, $node); $node->parentNode->removeChild($node); } echo $dom->saveHTML();
Output for 8.0.30, 8.1.22 - 8.1.28, 8.2.9 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body> <a class="popup-img left" title="lol" href="../img/product/name/img.jpg" style="background: url('../img/product/name/thumbs/100/img.jpg'); -webkit-background-size:cover; background-size:cover;"></a> </body></html>
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body> <a class="popup-img left" title="lol" href="../img/product/name/img.jpg" style="background: url('../img/product/name/thumbs/100/img.jpg'); -webkit-background-size:cover; background-size:cover;"></a> </body></html>
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.29, 8.1.0 - 8.1.21, 8.2.0 - 8.2.8
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body> <a class="popup-img left" title="lol" href="../img/product/name/img.jpg" style="background: url('../img/product/name/thumbs/100/img.jpg'); -webkit-background-size:cover; background-size:cover;"></a></body></html>

preferences:
178.87 ms | 403 KiB | 181 Q