php {{ }} 和 {!! 有什么区别?!!} 在 laravel 刀片文件中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35030977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:19:20  来源:igfitidea点击:

What is the difference between {{ }} and {!! !!} in laravel blade files?

phplaravellaravel-5.2laravel-blade

提问by Kumaran

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?

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

回答by Narendrasingh Sisodia

Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks.

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

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

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

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

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

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

<b>Narendra Sisodia</b>

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

但是如果它被访问,{!! $first !!}那么输出将是:

Narendra Sisodia

纳伦德拉·西索迪亚

回答by Sougata Bose

If you don't want the data to be escaped then use {!! !!}else use {{ }}.

如果您不想转义数据,请使用{!! !!}else use {{ }}

回答by Mehari

from the documentation:https://laravel.com/docs/5.1/blade

来自文档:https : //laravel.com/docs/5.1/blade

By default, Blade {{ }}statements are automatically sent through PHP's htmlentities function to prevent XSS attacks. If you do not want your data to be escaped, you may use the following syntax:

默认情况下,Blade{{ }}语句会通过 PHP 的 htmlentities 函数自动发送,以防止 XSS 攻击。如果您不希望您的数据被转义,您可以使用以下语法:

Hello, {!! $name !!}.

回答by Poorna Rao

To escape data use

逃避数据使用

{{ $data }}

If you don't want the data to be escaped use below

如果您不希望数据被转义,请使用下面的

{!! $data !!}

回答by Panagiotis Koursaris

Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks.

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

You can see more here:https://laravel.com/docs/master/blade

你可以在这里看到更多:https: //laravel.com/docs/master/blade