I want to remove all script element and here the code
<?php
$pageFile = <<<EOF
<!DOCTYPE html><html><body>
<script src="aa"></script>
<script src="bb"></script>
<script src="cc"></script>
<div>aaa</div>
</body></html>
EOF;
$dom = new DOMDocument();
$dom->loadHTML($pageFile);
foreach ($dom->getElementsByTagName('script') as $item) {
$item->parentNode->removeChild($item);
}
$pageFile = $dom->saveHTML();
echo $pageFile;
but there still 1 script element exist. You can try it online here
Result:
<!DOCTYPE html>
<html><body>
<script src="bb"></script><div>aaa</div>
</body></html>