Home  >  Article  >  php教程  >  一个不利用分词就可以实现的铭感词过滤功能

一个不利用分词就可以实现的铭感词过滤功能

PHP中文网
PHP中文网Original
2016-05-23 17:10:001130browse

php代码

<?php
/**
 * 敏感词汇过滤
 * User: konakona
 * Date: 12-11-28
 * Time: 下午4:37
 * 调用方式
 * if(false === SensitiveFilter::filter($content)){
 *      error("含有敏感词汇");
 * }
 */
 
class SensitiveFilter extends Think{
 
    public static $wordArr = array();
    public static $content = "";
 
    /**
     * 处理内容
     * @param $content
     *
     * @return bool
     */
    public static function filter($content){
        if($content=="") return false;
        self::$content = $content;
        empty(self::$wordArr)?self::getWord():"";
        foreach ( self::$wordArr as $row){
            if (false !== strstr(self::$content,$row)) return false;
        }
        return true;
    }
 
    public static function getWord(){
        self::$wordArr = include &#39;SensitiveThesaurus.php&#39;;
    }
 
}

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
Previous article:顺推,例子Next article:抓取文章列表