3v4l.org

run code in 200+ PHP versions simultaneously
<?php $html = <<<HTML <div> <img src="icons/example.svg"> <a href="http://www.example.com">a link</a> <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); $dom->substituteEntities = false; $xpath = new DOMXPath($doc); foreach ($xpath->query('//img/@src | //link/@href') as $attr) { $attr->value = "{{asset('" . $attr->value . ")'}}"; } echo $doc->saveHTML();
Output for 7.2.0 - 7.4.6
Warning: Creating default object from empty value in /in/ZHSFX on line 13 <div> <img src="%7B%7Basset('icons/example.svg)'%7D%7D"> <a href="http://www.example.com">a link</a> <link href="%7B%7Basset('css/example.css)'%7D%7D"> <iframe src="http://www.example.com/default.htm"></iframe> </div>