PHP使用preg_replace和preg_match过滤敏感词
代码1:
Copy to Clipboard引用的内容:
[www.bkjia.com]
$badstring="tmd|妈的|TNND|她娘的";
$string="你tmd说什么,她娘的,不是人";
echo preg_replace("/$badstring/i",'',$string);
?>
代码2:
Copy to Clipboard引用的内容:
[www.bkjia.com]
$badkey = "敏感词|敏感词B|敏感词C";
$string = "我是不含有敏感词的,我要发表";
if(preg_match("/$badkey/i",$string)){
echo "对不起,含有含有敏感字符,不允许发表";
}else{
//do something...
echo "帮客之家提示:可以通过 www.bkjia.com";
}
?>
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