高效的敏感词过滤方法(PHP)

方法一:

$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.";  
  } 

 

posted @ 2018-01-22 14:54  智昕  阅读(717)  评论(0编辑  收藏  举报