php 过滤敏感关键词

php 过滤敏感关键词

function badwords($content){
    $keywords=M("config")->where("name='badwords'")->getField("value");
    $badwords = explode(",",$keywords); //关键词的数组
    $badword1 = array_combine($badwords,array_fill(0,count($badwords),'***'));
    $str = strtr($content, $badword1);
    $pattern = "/(d{0})d{5}(d{0})/";
    $replacement = "$1****$2";
    $res =  preg_replace($pattern, $replacement, $str); //这个是去除连续的数字
    return $res;
}
原文地址:https://www.cnblogs.com/xqschool/p/6957322.html