“警告:遇到非数字值”错误

时间:2018-04-07 16:09:11

标签: php wordpress

我在运行查看计数器时遇到错误:

  

警告:在C:\ xampp \ htdocs \ tepetaklak \ wp-content \ themes \ gridlove \ core \ template-functions.php中遇到非数字值   在第163行

以下是代码:

case 'views':
                global $wp_locale;
                $thousands_sep = isset( $wp_locale->number_format['thousands_sep'] ) ? $wp_locale->number_format['thousands_sep'] : ',';
                if ( strlen( $thousands_sep ) > 1 ) {
                    $thousands_sep = trim( $thousands_sep );
                }
/*line163*/ $meta = function_exists( 'ev_get_post_view_count' ) ?  number_format_i18n( absint( str_replace( $thousands_sep, '', ev_get_post_view_count( get_the_ID() ) ) + gridlove_get_option( 'views_forgery' ) ) )  . ' '.__gridlove( 'views' ) : '';
                break;

感谢您的支持。

2 个答案:

答案 0 :(得分:1)

试试这个:(将字符串转换为int)

$num = (int) (str_replace( $thousands_sep, '', ev_get_post_view_count( get_the_ID() ) )) + (int)(gridlove_get_option( 'views_forgery' ));
$meta = function_exists( 'ev_get_post_view_count' ) ?  number_format_i18n( absint( $num ) )  . ' '.__gridlove( 'views' ) : '';

答案 1 :(得分:1)

你安装了php7.1或更高版本吗?

gridlove_get_option( 'views_forgery' )的类型是什么?

如果使用php7.1或更高版本,则必须将结果从str_replace转换为整数。+ 修改

您的代码应该是这样的

$meta = function_exists( 'ev_get_post_view_count' ) ?  number_format_i18n( absint( (int)str_replace( $thousands_sep, '', ev_get_post_view_count( get_the_ID() ) ) + (int)gridlove_get_option( 'views_forgery' ) ) )  . ' '.__gridlove( 'views' ) : '';