问题描述
我正在尝试nl2br
在Laravel 5.3中发送我的电子邮件.
I'm trying to nl2br
my email in Laravel 5.3.
Dear {{ $user->name }} {{ $user->last_name }}, <br><br>
{{ nl2br($request['message']) }}
<br><br>
Regards,<br><br>
但是结果是:
Dear John doe,
Blablabla<br /> <br /> Blablabla<br /> <br /> blablabla<br /> <br /> blablabla
如何确保<br />
确实是断线?
推荐答案
此表达式{{ $var }}
用于编码HTML字符,您应该执行以下操作:
This expression {{ $var }}
is used to encode HTML characters, you should do the following:
{!! nl2br(htmlspecialchars($request['message'])) !!}
htmlspecialchars()
:此代码对特殊字符进行编码,以避免安全问题
htmlspecialchars()
: this encodes the special characters to avoid security issues
nl2br()
:这会将新行转换为<br>
标签,但是在它被保护之后
nl2br()
: this transforms the new lines to <br>
tags, but AFTER it has already been secured
{!! !!}
:这告诉Blade在输出变量时不对HTML字符进行编码
{!! !!}
: this tells Blade to not encode HTML characters when outputting the variable
请注意,这与发送电子邮件无关,对于普通视图来说是相同的.
Note that this is not related to sending emails, it's the same thing for a normal view.
这篇关于电子邮件中的Laravel 5.3 nl2br的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!