<?php $html = <<<HTML <html> <head> <script type='text/javascript' src='/wp-includes/js/jquery/jquery.js?ver=1.8.3'></script> <script type='text/javascript' src='https://www.example.com/leave-this-alone'></script> <script language="JavaScript"> window.moveTo(0,0); window.resizeTo(screen.width,screen.height); </script> </head> </html> HTML; $workingUrl = 'https://www.example.com'; $dom = new DOMDocument; $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); foreach ($xpath->query("//script[@src and not(starts-with(@src,'http'))]") as $node) { $node->setAttribute('src', $workingUrl); } echo $dom->saveHTML();
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`