替换敏感词汇行为扩展!!

浏览:2188 发布日期:2013/11/22 分类:功能实现 关键字: 行为扩展
前台替换敏感词汇行为扩展
<?php
/**
 * Created by PhpStorm.
 * User: cony
 * Date: 13-11-18
 * Time: 下午8:53
 */
class FilterWordBehavior extends Behavior{

    protected $options=array(
        'FILTERWORD'=>true,
        'KEYWORDS'=>'',
        'REPLACEWORD'=>'***'
    );

    public function run(&$content){
        if(C('FILTERWORD.FILTERWORD'))
        $content = $this->FilterWordsContent($content);
    }
    /**
     * 模板内容替换
     * @access protected
     * @param string $content 模板内容
     * @return string
     */
    protected function FilterWordsContent($content) {
        $keywordstring=C('FILTERWORD.KEYWORDS');
        $keywordarray=explode(',',$keywordstring);
        $replaceword=C('FILTERWORD.REPLACEWORD');
        $replace=array();
        if(is_array($keywordarray)){
            foreach($keywordarray as $key=>$value){
                $replace[$value]=$replaceword;
            }
        }
        $content = str_replace(array_keys($replace),array_values($replace),$content);
        return $content;
    }

}
代码来源及使用方法:http://www.conist.com/bbs/forum.php?mod=viewthread&tid=12&extra=page%3D1
评论( 相关
后面还有条评论,点击查看>>