3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <div> <img src="/relative/url/img.jpg" /> <form action="/"></form> <form action="/contact-us/"></form> <a href='/relative/url/'>Note the Single Quote</a> <img src="//example.com/protocol-relative-img.jpg" /> </div> HTML; $domain = '//example.com'; $tagsAndAttributes = [ 'img' => 'src', 'form' => 'action', 'a' => 'href' ]; $dom = new DOMDocument; $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); foreach ($tagsAndAttributes as $tag => $attr) { foreach ($xpath->query("//{$tag}[not(starts-with(@{$attr}, '//'))]") as $node) { $node->setAttribute($attr, $domain . $node->getAttribute($attr)); } } echo $dom->saveHTML();

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
178.45 ms | 2277 KiB | 8 Q