Blade: escaping text and allowing new lines

你离开我真会死。 提交于 2019-11-27 10:15:39

问题


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.


回答1:


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




回答2:


You can use this

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


来源:https://stackoverflow.com/questions/28027236/blade-escaping-text-and-allowing-new-lines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!