Home >Backend Development >PHP Tutorial >PHP uses regular filtering js script code example_PHP tutorial

PHP uses regular filtering js script code example_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:29:56966browse

The matching rule cannot use "//i" because it cannot match newline characters, so multiple lines of js cannot be matched. Use "//i". The ? inside means to have as few repetitions as possible, that is, to match the nearest .

Source code example:

Copy code The code is as follows:


header("Content-type:text/html;charset=utf-8");
$str = '
Test php regular matches the js code Test php regular matches the js code Test php regular matches the js code Test php regular matches the js code Test php regular matches the js code Test php regular matches the js code


Test the php regular match to match the js code';

$preg = "//i";
$newstr = preg_replace($preg,"",$str,3); //The fourth one 3 in the parameter means replacement 3 times, the default is -1, replace all
echo $newstr;

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/768139.htmlTechArticleThe matching rule cannot use "/script.*/script/i" because it cannot match newline characters. There are so many lines of js that cannot be matched. Use "/script[sS]*?/script/i". The ? inside means as little as possible...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn