Matching rules cannot be "/<script.*<\/script>/i" because it does not match to line breaks, so many rows of JS will not match. To use "/<script[\s\s]*?<\/script>/i". What's inside? represents as little repetition as possible, that is, matching the nearest </script>.
Source code Example:
Copy Code code as follows:
<?php
Header ("Content-type:text/html;charset=utf-8");
$str = ' <script type= ' text/javascript ' src= ' dd.js ' ></script>
Test PHP match out of JS Code test PHP is matching off the JS code test PHP is matching off the JS Code test PHP is the match out of the matching JS code test PHP is the match out of the JavaScript testing of JS Code test PHP is matching out JS code
<script type= "Text/javascript" src= "123.js" ></script>
<script type= "Text/javascript" >
var AA = "Sdsds";
alert (AA);
</script>
Test PHP matches off the JS code ';
$preg = "/<script[\s\s]*?<\/script>/i";
$newstr = Preg_replace ($preg, "", $str, 3); 3 of the fourth argument replaces 3 times, the default is-1, replaces all
Echo $newstr;
?>