欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

PHP关键字过滤的函数

程序员文章站 2022-03-03 10:21:23
...
    /**
     * 关键字过滤
     */
    function keyfilter($content){
        $config = Config::get('memcache.1700');    
        $this->memcache = new \Memcache;
        $this->memcache->connect($config['host'], $config['port']);
        
        $data = $this->memcache->get('keyfilter');
        if ($data)
            $data = json_decode($data, true);
        
        if (empty($data)) {
            $result = Db::table('web_badkeys')->where("status = 1")->select();
            foreach ($result AS $key => $val) {
                $data[] = '/'.$val['title'].'/';        
            }
            $this->memcache->set('keyfilter', json_encode($data));
        }
        $content = preg_replace($data, '**', $content);
        return $content;
    }