<?php $homepage = "https://example.com/"; $html = '<img class="drt" src="100.png"><img src="../101.png"><img src="/102.png"><img src="103.png">'; $dom = new DOMDocument(); $dom->loadHTML($html); foreach ($dom->getElementsByTagName('img') as $img) { $src = $img->getAttribute('src'); $src = $homepage.basename($src); $img->setAttribute('src', $src); } // hacky way! remove unwanted doctype ect $ret = preg_replace('~<(?:!DOCTYPE|/?(?:html|body|head))[^>]*>\s*~i', '', $dom->saveHTML()); echo trim(str_replace('<meta http-equiv="Content-Type" content="text/html;charset=utf-8">', '', $ret)); // proper way! but you dont have correct DOM, no <body> // remove <!DOCTYPE //$dom->removeChild($dom->doctype); // remove <html><body></body></html> //$dom->replaceChild($dom->firstChild->firstChild->firstChild, $dom->firstChild); // //echo $dom->saveHTML();
You have javascript disabled. You will not be able to edit any code.