The matching rule cannot use "// <script. * </script>/I", because it cannot match the line break, so multiple lines of js won't match. To use "// <script [sS] *? <// Script> // I ". Inside? Indicates that there are as few duplicates as possible, that is, matching the latest script.
Source code example:
The code is as follows: |
Copy code |
<? Php Header ("Content-type: text // html; charset = utf-8 "); $ Str = '<script type = "text // javascript" src = "dd. js"> <// script> Test php regular expression matching js code <script type = "text // javascript" src = "123.js"> <// script> <Script type = "text // javascript"> Var aa = "sdsds "; Alert (aa ); <// Script> Test php regular expression matching js code '; Www.111Cn.net $ Preg = "// <script [sS] *? <// Script> // I ";
$ Newstr = preg_replace ($ preg, "", $ str, 3); // 3 in the fourth parameter indicates that it is replaced three times. The default value is-1. Replace all Echo $ newstr; ?>
|