php - 什么是正确的 laravel 语法

在 laravel Blade 中使用表单时,此语法有效

{!!Form::token()!!} //with double exclamation mark

用于包含远程 js 文件,这是可行的
<script src="{{ asset('js/register.js')}}" ></script>

没有感叹号。事实上,感叹号创建的问题.js 文件未找到错误。

我想知道这两种语法的区别。何时使用哪一种?

最佳答案

来自 Laravel 的文档:

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:

Hello, {!! $name !!}.

Note: Be very careful when echoing content that is supplied by users of your application. Always use the double curly brace syntax to escape any HTML entities in the content.


使用 {{ $var }}相当于<?php echo htmlentities($var);?>
使用 {!! $var !!}}相当于<?php echo $var;?>
一般来说,你会使用 {{ }}大多数情况下,除非有特殊字符自 htmlentities 以来未显示正在逃离他们。只有在这些情况下,您才会使用 {!! !!}} .

希望这可以帮助。

https://stackoverflow.com/questions/36240336/

相关文章:

python - 哪个更快 np.vstack、np.append、np.concatenate 或

python - NumPy - 扩展和重复

curl - 使用 Curl for Dynamics Nav 验证 OData

maven - 使用 Java 5 运行的 JAXB 编码异常 javax.xml.stream.F

unix - 使用 grep 或 awk 查找在不同行上同时包含 "a"和 "b"的文件

c - 大量递归函数背后实际上发生了什么?

r - 在 R 中切片数据帧的第二半

c++ - 将OpenGL实例化图形与移动对象一起使用

regex - Powershell foreach 路径找不到文件

linux - 更改 IP 后 RIAK 节点未启动