{{ }} 和 {!! 有什么区别?!!} 在 laravel 刀片文件中? [英] What is the difference between {{ }} and {!! !!} in laravel blade files?

查看:30
本文介绍了{{ }} 和 {!! 有什么区别?!!} 在 laravel 刀片文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在laravel框架中我们可以使用blade在html文件中添加PHP代码.
我们同时使用 {{ }}{!!!!} Laravel 刀片文件中的语法.
它们有什么区别?

In the laravel framework we can use blade to add PHP code in html file.
We are using both {{ }} and {!! !!} syntax in blade files of Laravel.
What is the difference between them?

推荐答案

Blade {{ }} 语句通过 PHP 的 htmlentities 函数自动发送,以防止 XSS 攻击.

如果您将数据从控制器传递到具有一些 HTML 样式的视图,例如:

If you pass data from your Controller to a View with some HTML styling like:

$first = "<b>Narendra Sisodia</b>";

在 Blade 中使用 {{ $first }} 访问它,然后输出将是:

And it is accessed, within Blade, with {{ $first }} then the output'll be:

<b>Narendra Sisodia</b>

但是如果用{!!$first !!} 然后输出将是:

But if it is accessed with {!! $first !!} then the output'll be:

纳伦德拉·西索迪亚

这篇关于{{ }} 和 {!! 有什么区别?!!} 在 laravel 刀片文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆