- html_entity_decode: documentation ( source)
- preg_replace: documentation ( source)
<?php
$str = '<!doctype html>
<html>
<head>
<script type="text/javascript">alert(fasdfsd)</script>
<meta charset="utf-8">
<script type="text/javascript">
var fasdfsd="fasdfsd";
</script>
<script type="text/javascript" src="http://google.adv.js"></script>
<title>
hey
</title>
<script>
alert("hello");
</script>
<script type="text/javascript" src="lfasd.js"></script>
</head>
<body>
hey
</body>
</html>';
$str = preg_replace("@<script[^>]*?>.*?</script>@siu","\n",$str);
$str = preg_replace("/(\n)+/","\n",$str);
echo html_entity_decode($str);