I'm following the excellent laravel guide on Laracasts and have gotten to the point where we're outputting song titles from a mysql database in video 7.
我正在关注Laracasts的优秀laravel指南,并且已经达到了我们从视频7中的mysql数据库输出歌曲标题的程度。
I wanted to go ahead and add the lyrics which I've done just fine.
我想继续添加我做得很好的歌词。
Now I'd just like to format it a little better, to add new lines where required.
现在我只想更好地格式化它,在需要的地方添加新行。
I've attempted to use str_replace in my view in this manner;
我试图以这种方式在我的视图中使用str_replace;
<p>{{str_replace("\r","\n", $song->lyrics)}}</p>
But nothing appears to happen. If I use
instead of \n, I can see that the carriage return is detected in the correct places, but my output appears like this;
但似乎没有任何事情发生。如果我使用而不是\ n,我可以看到在正确的位置检测到回车,但我的输出显示如下;
looking oh so pretty,<br> I've just got to find my way.<br>
Where the < br>'s are just output as normal text.
其中
只是作为普通文本输出。
Can anyone tell me if I'm approaching this in the right way? I've tried double and triple curly braces and I think I may be forgetting something that mentioned an exclamation mark, but I can't seem to find where it was mentioned again.
任何人都可以告诉我,如果我以正确的方式接近这个吗?我已经尝试了双花和三花括号,我想我可能会忘记提到感叹号的东西,但我似乎无法找到它再次提到的地方。
Any help would be appreciated.
任何帮助,将不胜感激。
1 个解决方案
#1
In Laravel 5 you should use {!! !!}
to output variable without escaping:
在Laravel 5你应该使用{!! !!}输出变量而不转义:
{!! str_replace("\r","\n", $song->lyrics) !!}
Read more: http://laravel.com/docs/master/upgrade#upgrade-5.0 (Blade Tag Changes section)
阅读更多:http://laravel.com/docs/master/upgrade#upgrade-5.0(刀片标签更改部分)
#1
In Laravel 5 you should use {!! !!}
to output variable without escaping:
在Laravel 5你应该使用{!! !!}输出变量而不转义:
{!! str_replace("\r","\n", $song->lyrics) !!}
Read more: http://laravel.com/docs/master/upgrade#upgrade-5.0 (Blade Tag Changes section)
阅读更多:http://laravel.com/docs/master/upgrade#upgrade-5.0(刀片标签更改部分)