3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <p>Some random text <img src="anything.jpg"> text <iframe data-whoops="<img" src="anything.jpg"></iframe></p> HTML; define('DOC_ROOT', 'www.example.com/'); echo "With regex:\n"; echo preg_replace('/<img([^>]*)src=["\']([^"\'\\/][^"\']*)["\']/', '<img\1src="'.DOC_ROOT.'\2"', $html); echo "\n\n---\n\nWith a parser:\n"; $dom = new DOMDocument; $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); foreach ($dom->getElementsByTagName('img') as $img) { $img->setAttribute('src', DOC_ROOT . $img->getAttribute('src')); } echo $dom->saveHTML();
Output for git.master, git.master_jit, rfc.property-hooks
With regex: <p>Some random text <img src="www.example.com/anything.jpg"> text <iframe data-whoops="<img" src="www.example.com/anything.jpg"></iframe></p> --- With a parser: <p>Some random text <img src="www.example.com/anything.jpg"> text <iframe data-whoops="&lt;img" src="anything.jpg"></iframe></p>

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:
31.9 ms | 406 KiB | 5 Q