Home > php教程 > PHP源码 > body text

ThinkPHP敏感词汇过滤

PHP中文网
Release: 2016-05-25 17:09:07
Original
2979 people have browsed it

如果内容中包含敏感词汇,则返回False,否则返回True。 
很简单的代码。 
请将文件放置于 "项目/ORG/SensitiveFilter.class.php"下。 

其中 “ SensitiveThesaurus.php”是一个敏感词汇数组,大家可以任意添加内容。 

1. [代码][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;;
    }

}
Copy after login

2. [文件]     SensitiveThesaurus.php 

ThinkPHP敏感词汇过滤SensitiveThesaurus.rar                        

3. [图片] 被拦截.jpg    

ThinkPHP敏感词汇过滤

                                           

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!