如何解码HTML特殊字符和字符串限制?
此行不起作用:
<p>{!!\Str::limit($event->description,180,"..")!!}<a href="#">View Detail</a></p>
但是如果我正常地将其用于字符串限制,它将:
<p>{{\Str::limit($event->description,180,"..")}}<a href="#">View Detail</a></p>
上面的行适用于字符串限制,但不能解码。
答案 0 :(得分:0)
目前尚不清楚$event->description
包含什么。另外,还不清楚\Str
代表什么,甚至不清楚您使用的是哪个版本的Laravel。以下示例假定您的意思是Illuminate\Support\Str
,并且在版本5.8.XX上,并且我包括两个不同的描述变量。
$description = "<p><strong>Lorem ipsum</strong> dolor sit amet, consectetur adipiscing elit. "Ut augue orci, pellentesque at metus sed, tempor ultrices diam." Quisque tempor ullamcorper nunc, vitae efficitur justo tristique sed. Sed ac orci condimentum, viverra mi quis, pharetra sapien. Suspendisse nec nisi sem. </p>\n";
$descEncoded = "<p><strong>Lorem ipsum</strong> dolor sit amet, consectetur adipiscing elit. &quot;Ut augue orci, pellentesque at metus sed, tempor ultrices diam.&quot; Quisque tempor ullamcorper nunc, vitae efficitur justo tristique sed. Sed ac orci condimentum, viverra mi quis, pharetra sapien. Suspendisse nec nisi sem. Sed porta finibus posuere. Nunc a libero vitae mi ornare interdum.</p>";
html_entity_decode:
{!!\Illuminate\Support\Str::limit(html_entity_decode($description),180,"...")!!}
{!!\Illuminate\Support\Str::limit(html_entity_decode($descEncoded),180,"...")!!}
htmlspecialchars_decode:
{!!\Illuminate\Support\Str::limit(htmlspecialchars_decode($description),180,"...")!!}
{!!\Illuminate\Support\Str::limit(htmlspecialchars_decode($descEncoded),180,"...")!!}
希望这对您的事业有所帮助。如果您更详细地更新问题,我可以根据需要调整答案。