【问题标题】:php code update split and count not workingphp代码更新拆分和计数不起作用
【发布时间】:2021-04-29 21:45:45
【问题描述】:

我从 5.6 到 7.4.11 做了一些代码更新,这部分代码停止工作,它没有抛出错误,所以我有点不清楚我哪里出错了。

原始代码

<?
 $mapdesc = get_post_meta( $post->ID, 'the_mapdesc');
 if (count($maxmapdesclength) > 0 )
 { 
  if (strlen($mapdesc[0]) > $maxmapdesclength) $mapdesc[0] = substr($mapdesc[0], 0, $maxmapdesclength-3) . '...';
    $arrmapdesc = split("\n", $mapdesc[0]);
    $mymapdesc = "";
    for ($i=0; $i<count($arrmapdesc) && $i<3; $i++)
     $mymapdesc .= $arrmapdesc[$i] . '<br />';
    
    print $mymapdesc;
 }

更新代码

<?
 $mapdesc = get_post_meta( $post->ID, 'the_mapdesc');
 // if (count($maxmapdesclength) > 0 )
 if (is_countable($maxmapdesclength) && count($maxmapdesclength) > 0 )
 { 
  if (strlen($mapdesc[0]) > $maxmapdesclength) $mapdesc[0] = substr($mapdesc[0], 0, $maxmapdesclength-3) . '...';
    $arrmapdesc = explode("\n", $mapdesc[0]);
    $mymapdesc = "";
    for ($i=0; $i<count($arrmapdesc) && $i<3; $i++)
     $mymapdesc .= $arrmapdesc[$i] . '<br />';
    
    print $mymapdesc;
 }

【问题讨论】:

  • 那么错误是什么?
  • 错误是什么都没有显示,错误日志是干净的,看起来问题出在is_countable行又名print $mymapdesc;没有输出任何东西

标签: php split count


【解决方案1】:

我怀疑您对$maxmapdesclength 的使用有问题。

if 语句中,您将其视为一个 Countable|array,然后在 substr 函数中您期望它像一个数字一样工作。

【讨论】:

  • 如果我保持爆炸并恢复计数代码工作但通过 php 警告
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-07
  • 2020-01-13
  • 2017-03-06
  • 1970-01-01
相关资源
最近更新 更多