zoukankan      html  css  js  c++  java
  • 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.";
    }*/

  • 相关阅读:
    java URL、HTTP与HTML+CSS
    JDK的图文安装教程
    Java之Tomcat、Dynamic web project与Servlet
    Java基础ArrayList、Servlet与Filter
    JavaMath方法、服务器与Tomcat安装与配置步骤
    关于navicat 系列软件一点击菜单栏就闪退
    Java基础之MySQL数据库与JDBC
    Java中的常用方法
    Java基础之Calendar类、JNDI之XML
    JAVAWEB基础模块开发顺序与数据访问对象实现类步骤
  • 原文地址:https://www.cnblogs.com/wenxinphp/p/6307214.html
Copyright © 2011-2022 走看看