Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何解码具有字符串限制的html特殊字符?_Php_Laravel - Fatal编程技术网

Php 如何解码具有字符串限制的html特殊字符?

Php 如何解码具有字符串限制的html特殊字符?,php,laravel,Php,Laravel,如何解码HTML特殊字符和字符串限制 此行不起作用: <p>{!!\Str::limit($event->description,180,"..")!!}<a href="#">View Detail</a></p> {!!\Str::limit($event->description,180,“…”) 但如果我正常使用它作为字符串限制,它将: <p>{{\Str::limit($event->description,1

如何解码HTML特殊字符和字符串限制

此行不起作用:

<p>{!!\Str::limit($event->description,180,"..")!!}<a href="#">View Detail</a></p>
{!!\Str::limit($event->description,180,“…”)

但如果我正常使用它作为字符串限制,它将:

<p>{{\Str::limit($event->description,180,"..")}}<a href="#">View Detail</a></p>
{{\Str::limit($event->description,180,“…”)}


上面的行可以使用字符串限制,但不能解码

尚不完全清楚
$event->description
包含什么内容。此外,还不完全清楚
\Str
代表什么,甚至不清楚您使用的是什么版本的Laravel。下面的示例假设您的意思是
illumb\Support\Str
和版本5.8.XX,我包括两个不同的描述变量

$description = "<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. </p>\n";

$descEncoded = "&lt;p&gt;&lt;strong&gt;Lorem ipsum&lt;/strong&gt; dolor sit amet, consectetur adipiscing elit. &amp;quot;Ut augue orci, pellentesque at metus sed, tempor ultrices diam.&amp;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.&lt;/p&gt;";

htmlspecialchars\u解码:

{!!\Illuminate\Support\Str::limit(html_entity_decode($description),180,"...")!!}
{!!\Illuminate\Support\Str::limit(html_entity_decode($descEncoded),180,"...")!!}
{!!\Illuminate\Support\Str::limit(htmlspecialchars_decode($description),180,"...")!!}
{!!\Illuminate\Support\Str::limit(htmlspecialchars_decode($descEncoded),180,"...")!!}


希望这有助于你的事业。如果您用更多细节更新问题,我可以根据需要调整答案。

还不完全清楚
$event->description
包含什么内容。此外,还不完全清楚
\Str
代表什么,甚至不清楚您使用的是什么版本的Laravel。下面的示例假设您的意思是
illumb\Support\Str
和版本5.8.XX,我包括两个不同的描述变量

$description = "<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. </p>\n";

$descEncoded = "&lt;p&gt;&lt;strong&gt;Lorem ipsum&lt;/strong&gt; dolor sit amet, consectetur adipiscing elit. &amp;quot;Ut augue orci, pellentesque at metus sed, tempor ultrices diam.&amp;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.&lt;/p&gt;";

htmlspecialchars\u解码:

{!!\Illuminate\Support\Str::limit(html_entity_decode($description),180,"...")!!}
{!!\Illuminate\Support\Str::limit(html_entity_decode($descEncoded),180,"...")!!}
{!!\Illuminate\Support\Str::limit(htmlspecialchars_decode($description),180,"...")!!}
{!!\Illuminate\Support\Str::limit(htmlspecialchars_decode($descEncoded),180,"...")!!}


希望这有助于你的事业。如果您用更多细节更新问题,我可以根据需要调整答案。

您想在屏幕上显示什么?$event->description是否包含HTML标记?你想让这些HTML标记以HTML格式显示在屏幕上吗?如果你想解码HTML特殊字符,你可以在Str::limit()函数中使用PHP函数:htmlspecialchars\u decode。你到底想在屏幕上显示什么?$event->description是否包含HTML标记?是否希望这些HTML标记以HTML格式显示在屏幕上?如果要解码HTML特殊字符,可以在Str::limit()函数中使用PHP函数:htmlspecialchars\u decode。