码迷,mamicode.com
首页 > 其他好文 > 详细

非法词屏蔽

时间:2016-02-17 19:03:11      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

<?php
class Text_Filter
{
    var $words;  //文字
    function Text_Filter()
    {
        $this->words=NULL;
    }
    
    function wordsFilter(&$message=null, &$matche_row=array())
    {
        //$matche_row 非法词组
        if(empty($this->words))
        {
            global $config;
            @include_once($config[‘webroot‘].‘/config/filter.inc.php‘);
            $this->words =& $_CACHE[‘word_filter‘];
        }
        else
        {
            
        }

        $message = empty($this->words[‘filter‘]) ? $message : @preg_replace($this->words[‘filter‘][‘find‘], $this->words[‘filter‘][‘replace‘], $message);

        if($this->words[‘banned‘] && preg_match($this->words[‘banned‘], $message, $matche_row))
        {
            echo "<div align=‘center‘>Content contains illegal characters.<br>";
            foreach($matche_row as $v)
            {
                echo $v.‘,‘;
            }
            echo "<br> <a href=‘javascript:history.back();‘ > Back </a> </div>";
            die;//有非法词
        }
        else
        {
            return $message;//被替换后的信息
        }
    }
}
?>

 

非法词屏蔽

标签:

原文地址:http://www.cnblogs.com/Asatic/p/5196092.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!