在 Laravel PHP 括号之间插入 HTML 代码。

huangapple go评论60阅读模式
英文:

Insert html code in between a Laravel PHP bracket

问题

我该如何在Laravel PHP括号内的字符串之间插入HTML代码或换行符?

`{{ __('这个词在顶部' . '<br/>' . '这个词将在下方') }}`

类似这样

我尝试插入HTML代码,但不起作用。

英文:

How can I insert html code or line break in between a string inside the Laravel PHP bracket?

`{{ __('this word on top' . <br/> . 'this word will be below') }}`

Something like this

I tried putting the html code but it doesn't work

答案1

得分: 1

默认情况下,Blade {{ }} 语句会自动通过 PHP 的 htmlspecialchars 函数进行转义,以防止跨站脚本攻击。如果您不希望数据被转义,可以使用以下语法:

{!! __('这个词在上面 <br/> 这个词将在下面') !!}。

在输出应用程序用户提供的内容时要非常小心。通常,您应该使用转义的双大括号语法来防止在显示用户提供的数据时发生跨站脚本攻击。
有关更多信息,请参阅 Laravel 官方文档 https://laravel.com/docs/10.x/blade

英文:

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

{!! __(&#39;this word on top &lt;br/&gt; this word will be below&#39;) !!}.

Be very careful when echoing content that is supplied by users of your application. You should typically use the escaped, double curly brace syntax to prevent XSS attacks when displaying user supplied data.
For more information refer the laravel official docs https://laravel.com/docs/10.x/blade

huangapple
  • 本文由 发表于 2023年6月12日 14:39:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76454120.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定