Home >Backend Development >PHP Tutorial >php过滤敏感词的示例_PHP

php过滤敏感词的示例_PHP

WBOY
WBOYOriginal
2016-06-01 11:55:11788browse

复制代码 代码如下:
$badword = array(
    '张三','张三丰','张三丰田'
);
$badword1 = array_combine($badword,array_fill(0,count($badword),'*'));
$bb = '我今天开着张三丰田上班';
$str = strtr($bb, $badword1);
echo $str;

复制代码 代码如下:
$hei=array(
'中国',
'日本'
);
$blacklist="/".implode("|",$hei)."/i";
$str="中国一是一个很好的国家";
if(preg_match($blacklist, $str, $matches)){
    print "found:". $matches[0];
  } else {
    print "not found.";
  }

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