替换敏感词汇行为扩展!!
程序员文章站
2024-04-02 20:31:40
...
前台替换敏感词汇行为扩展
/**
* 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 AD:真正免费,域名+虚机+企业邮箱=0元
推荐阅读