1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > html中出现的script失效

html中出现的script失效

时间:2021-10-24 13:05:33

相关推荐

html中出现的script失效

如果在Controller中出现script代码类似

$hello_str='Hello God<script>alert(3);</script>';

那么我不希望在传给view的时候出现弹框,那么就在view文件中使用

use yii\helpers\Html;

并且输出时使用Html::encode

<?=Html::encode($view_hello_str);?>

还有一种方法就是过滤调script代码:

use yii\helpers\HtmlPurifier;

然后:

<?=HtmlPurifier::process($view_hello_str);?>

输出时只有Hello God

使用该方法的目的是为了防止用户恶意传入参数

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。