php Blade:转义文本并允许换行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28027236/
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
Blade: escaping text and allowing new lines
提问by lesssugar
I have a user-input text displayed on one of the pages. I want to allow new lines, though. How do I display the text, so it is escapedAND allows new lines?
我在其中一页上显示了用户输入的文本。不过,我想允许新行。如何显示文本,以便对其进行转义并允许换行?
I used nl2br()and Blade's tripple brackets {{{$text}}}, however, obviously, the tripple brackets escape <br/>tags as well.
我使用了nl2br()和 Blade 的三重括号{{{$text}}},但是,显然,三重括号也转义了<br/>标签。
Is there a way to combine escaping and HTML's new lines using Blade?
有没有办法使用 Blade 将转义和 HTML 的新行结合起来?
Thanks.
谢谢。
回答by lukasgeiter
You can do the escaping first, using e()and then apply nl2br():
您可以先进行转义,e()然后使用然后应用nl2br():
{{ nl2br(e($text)) }}
e()is the function Blade uses when compiling triple brackets
e()是 Blade 在编译三重括号时使用的函数
回答by Salar
You can use this
你可以用这个
{!! nl2br(e($text)) !!}
回答by pankaj kumar
in simple approach you can use it in bladeFile
以简单的方法,您可以在刀片文件中使用它
{!! nl2br(e($onlineSetting->instruction)) !!}
{!!nl2br(e($onlineSetting->instruction)) !!}

