How to remove every
<script></script>
Element in a HTML file? I tried the following regex:
preg_replace("/<script.*\/script>/", "", $html);
But it only works when the code is in just 1 single line. When a (newline) occurs it doesn't want to work. Any ideas?? Thanks!
Add the s modifier to your regex. The s modifier include newlines in "." Wildcard.
But you can think about some html sanitizers like htmlpurifier or simply use strip_tags if you want to remove some malicious code from html input
You could do this :
$HTML = str_replace(array("", "
", "
"), '', $HTML);
preg_replace("/<script.*\/script>/", "", $html);
Remove all breakline before. Problem solved.