malike 发表于 2018-2-11 12:08:22


            本文实例讲述了Yii净化器CHtmlPurifier用法。分享给大家供大家参考,具体如下:
1. 在控制器中使用:
public function actionCreate()
{
$model=new News;
$purifier = new CHtmlPurifier();
$purifier->options = array(
    'URI.AllowedSchemes'=>array(
            'http' => true,
            'https' => true,
    ),
       'HTML.Allowed'=>'div',
);
if(isset($_POST['News']))
{
    $model->attributes=$_POST['News'];
    $model->attributes['content'] = $purifier->purify($model->attributes['content']);
    if($model->save())
      $this->redirect(array('view','id'=>$model->id));
}
}
页: [1]
查看完整版本: Yii净化器CHtmlPurifier用法示例(过滤不良代码)