• PHP敏感词过滤


    --------------------------------------------------------------------------------------------------

    $str = "百度http://www.baidu.com,腾讯http://www.qq.com,新浪http://www.sina.com.cn/";;
    $arr = array("/百度/", "/腾讯/", "/新浪/");
    $prg = '***';
    $str = preg_replace($arr, $prg, $str);
    echo $str;

    --------------------------------------------------------------------------------------------------

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

    ---------------------------------------------------------------------------------------------------------------------------------------------------------

    /*function transgress_keyword($content, $Sensitivewords){ //定义处理违法关键字的方法
    $keyword = $Sensitivewords; //定义敏感词
    $m = 0;
    for($i = 0; $i < count ( $keyword ); $i ++) { //根据数组元素数量执行for循环
    //应用substr_count检测文章的标题和内容中是否包含敏感词
    if (substr_count ( $content, $keyword [$i] ) > 0) {
    $m ++;
    }
    }
    return $m; //返回变量值,根据变量值判断是否存在敏感词
    }

    if (transgress_keyword($detail, $Sensitivewords)> 0) { //判断返回值大于0说明包含敏感词
    echo "<script>alert('您输入的内容中含有敏感词');</script>";
    } */
    //-----------------------------------------------------------------------------------------------------------
    /*$num = 0;//定义子串出现次数
    //内容
    $content=$detail;
    //循环检测
    for($i = 0; $i < count($Sensitivewords); $i ++) {
    //计算子串在字符串中出现的次数
    if (substr_count ($content, $Sensitivewords[$i]) > 0) {
    $num ++;
    }
    }
    if($num>0){
    echo "有敏感词存在!";
    }*/
    //-----------------------------------------------------------------------------------------------------------
    /*$blacklist="/".implode("|",$Sensitivewords)."/i";
    if(preg_match($blacklist, $detail, $matches)){
    print "found:". $matches[0];
    } else {
    print "not found.";
    }*/

  • 相关阅读:
    SqlServer_小工具_时间格式化
    SqlServer_小工具_字符填充(左)
    SqlServer_小工具_获取北京时间
    JS写入Json到CSV并下载
    写入数据到CSV
    写入数据到Excel
    批量插入数据
    Json填充Object工具
    Json|XMl|Object互相转化-小工具
    TODO:用python实现aws签名
  • 原文地址:https://www.cnblogs.com/wenxinphp/p/6307214.html
Copyright © 2020-2023  润新知