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'; $targets = [ "//img[not(starts-with(@src, '//'))]", "//form[not(starts-with(@action, '//'))]", "//a[not(starts-with(@href, '//'))]" ]; $dom = new DOMDocument; $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); foreach ($xpath->query(implode('|', $targets)) as $node) { if ($src = $node->getAttribute('src')) { $node->setAttribute('src', $domain . $src); } elseif ($action = $node->getAttribute('action')) { $node->setAttribute('action', $domain . $action); } else { $node->setAttribute('href', $domain . $node->getAttribute('href')); } } 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:
185.03 ms | 406 KiB | 5 Q