刀片:转义文字并允许新行 [英] Blade: escaping text and allowing new lines

查看:119
本文介绍了刀片:转义文字并允许新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在其中一个页面上显示了一个用户输入的文本。我想允许新的线,但是。如何显示文本,因此转义允许新行



我使用 nl2br()和刀片的三角支架 {{$ {$ text}}} ,但是显然, $ c>< br /> 标签。



有没有办法使用刀片组合转义和HTML的新行? / p>

谢谢。

解决方案

您可以先转义, code> e()然后申请 nl2br()

  {{nl2br(e($ text))}} 

e()是编译三重括号时刀片使用的功能


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 escaped AND allows new lines?

I used nl2br() and Blade's tripple brackets {{{$text}}}, however, obviously, the tripple brackets escape <br/> tags as well.

Is there a way to combine escaping and HTML's new lines using Blade?

Thanks.

解决方案

You can do the escaping first, using e() and then apply nl2br():

{{ nl2br(e($text)) }}

e() is the function Blade uses when compiling triple brackets

这篇关于刀片:转义文字并允许新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆