【问题标题】:Wordpress PHP Warning: A non-numeric value encounteredWordpress PHP 警告:遇到非数字值
【发布时间】:2020-07-16 22:30:17
【问题描述】:

一段时间以来,我一直收到以下错误:

PHP Warning:  A non-numeric value encountered in /home/user/public_html/wp-content/themes/mytheme/content-one.php on line 29
PHP Warning:  A non-numeric value encountered in /home/user/public_html/wp-content/themes/mytheme/content-one.php on line 30

这些行是:

$minutes = floor($duration_in_seconds / 60);
$seconds = $duration_in_seconds % 60;

PHP 版本:7.3.20

谁能帮助我一些建议,如何解决这个问题?谢谢!

【问题讨论】:

  • 看来$duration_in_seconds 不包含数值,因此数学运算失败。我建议您打印它们的值以查看发生了什么。
  • 一切看起来都很好。我不知道我错在哪里。 $duration_in_seconds = get_post_meta($post->ID, 'duration', true); $minutes = floor($duration_in_seconds / 60); $seconds = $duration_in_seconds % 60; echo $minutes . ":" . str_pad($seconds, 2, "0", STR_PAD_LEFT);

标签: php wordpress error-handling


【解决方案1】:

$duration_in_seconds 可能是一个字符串,修复它的简单方法是:

$duration_in_seconds = intval($duration_in_seconds, 10)

【讨论】:

  • 感谢您的回答!现在我收到了这个错误PHP Parse error: syntax error, unexpected '$minutes'
  • @user2151960 在右括号后添加分号)
  • 感谢您的建议。我这样做了:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-04
  • 2023-03-29
  • 1970-01-01
  • 2018-05-03
  • 1970-01-01
相关资源
最近更新 更多