3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <div> Here is an img tag with no qs <img src="http://www.example.com/a.jpg">, an img with no src <img title="to be determined">, and here is another with a qs <img src="http://www.example.com/b.jpg?height=900">. Here is a <iframe src="http://www.example.com/c.jpg?foo=bar"></iframe> and a submit button <input type="image" src="http://www.example.com/d.jpg?boo=far&what=now" alt="Submit"> </div> HTML; $newUrl = 'https://www.example.com/new.jpg'; $dom = new DOMDocument(); libxml_use_internal_errors(true); $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); foreach ($xpath->query("//img/@src") as $src) { $src->value = $newUrl; } echo $dom->saveHTML();

preferences:
60.83 ms | 404 KiB | 5 Q