3v4l.org

run code in 200+ PHP versions simultaneously
<?php $html = <<<HTML <div> <img src="icons/example.svg"> <a href="http://www.example.com"> <link href="css/example.css"> <iframe src="http://www.example.com/default.htm"></iframe> </div> HTML; $doc = new DOMDocument(); $doc->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($doc); foreach ($xpath->query('//img/@src') as $attr) { $attr->value = "{{asset('" . $attr->value . ")'}}"; } echo $doc->saveHTML();
Output for 7.2.0 - 7.4.6
<div> <img src="%7B%7Basset('icons/example.svg)'%7D%7D"> <a href="http://www.example.com"> <link href="css/example.css"> <iframe src="http://www.example.com/default.htm"></iframe> </a></div>