I'm looking for a way to remove all JavaScripts tags from a html string.
Following regex works fine, but I would like to add an exception:
$html = preg_replace('#<script[^>]*>.*?</script>#is', '', $html);
How can I add a rule that scripts of a type text/html are getting ignored?
<script type="text/html" ... > ... </script>
Any suggestion?
Thanks in advance.
preg_replaceallow you to specify theeflag on the regular expression so that the replacement string is treated as code. Can't you use that with a replacement expression that looks for thetype="text/html"and returns the whole script tag if it's there and blank otherwise.