PHP8: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given

huangapple go评论59阅读模式
英文:

PHP8: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given

问题

我正在使用以下代码,此前一直有效,但在升级到PHP8后,出现以下错误:

Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given
$content = apply_filters('the_content', get_the_content());

$content_table = explode('</p>', $content);

$content_table[3] .= $spot1;
$content_table[6] .= $spot2;
$content_table[9] .= $spot3;
$content_table[12] .= $spot4;
$content_table[15] .= $spot5;

$content2 = implode('</p>', $content_table);

echo $content2;

如何修复这个问题?

英文:

I am using the following code, which has been working previously, but after upgrading to PHP8 I get the error of:

Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given
$content = apply_filters( &#39;the_content&#39;, get_the_content() );
		
$content_table = explode(&quot;&lt;/p&gt;&quot;, $content);

$content_table[3] .= $spot1;
$content_table[6] .= $spot2;
$content_table[9] .= $spot3;
$content_table[12] .= $spot4;
$content_table[15] .= $spot5;

$content2 = implode($content_table, &quot;&lt;/p&gt;&quot;);
		
echo $content2;

How can I fix this?

答案1

得分: 1

Sure, here's the translated content:

最后很简单,只需反转implode语句:

$content2 = implode("&lt;/p&gt;", $content_table);
英文:

Simple enough in the end, just had to reverse the implode statement:

$content2 = implode(&quot;&lt;/p&gt;&quot;, $content_table);

huangapple
  • 本文由 发表于 2023年6月15日 13:13:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76479305.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定