如何使字符串尊重换行符 <br />



目前我有以下数据来自laravel中的mysql数据库。

"hi this is my text I appear this way in the database
• I have some points
• Like so
• And another"

我希望在for each循环中以这种方式显示数据,该循环拉动字符串并显示它。为了实现这一点,我尝试了:

<p class="details-description">{{ str_replace("•", "<br /> •", $d->description) }}</p>

我的逻辑是,我会在每个项目之前用break代替•。然而,在渲染的html中,它显示如下:

"hi this is my text I appear this way in the database
<br /> • I have some points
<br /> • Like so
<br /> • And another"

你知道我该怎么做吗?

您可以使用nl2br()并使用带有{!!语法的原始过滤器(如果这是刀片(

<p> {!! nl2br($d->description) !!} </p>

最新更新