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();
Output for git.master, git.master_jit, rfc.property-hooks
<div> <img src="//example.com/relative/url/img.jpg"> <form action="//example.com/"></form> <form action="//example.com/contact-us/"></form> <a href="//example.com/relative/url/">Note the Single Quote</a> <img src="//example.com/protocol-relative-img.jpg"> </div>

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
108.87 ms | 406 KiB | 5 Q