Matching rules can not be used "/<script.*<\/script>/i", because it does not match to the newline character, then the multi-line JS will not be matched off.
To use "/<script[\s\s]*?<\/script>/i". What's inside? means as little repetition as possible, that is, matching the nearest </script>.
Source code Example:
.The code is as follows:
<?php
Header ("Content-type:text/html;charset=utf-8");
$str = ' <script type= ' Text/javascript "src=" Dd.js "></script>
Test PHP regular match out JS code test PHP regular match out JS code test PHP regular match out JS code test PHP regular match out JS code test PHP regular match out JS code test PHP regular match out JS code
<script type= "Text/javascript" src= "123.js" ></script>
<script type= "Text/javascript" >
var AA = "Sdsds";
alert (AA);
</script>
Test PHP regular match the JS Code ';
$preg = "/<script[\s\s]*?<\/script>/i";
$newstr = Preg_replace ($preg, "", $str, 3); The fourth parameter, 3, replaces 3 times, the default is-1, replaces all
Echo $newstr;
?>
PHP uses regular filter JS script code example