- htmlentities: documentation ( source)
- preg_replace: documentation ( source)
<?php
$str = '<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>
hey
</title>
<script>
alert("hello");
</script>
</head>
<body>
hey
</body>
</html>';
$str = preg_replace("@<script[^>]*?>.*?</script>@siu","",$str);
echo htmlentities($str);