在循环通过数组尝试将时间戳转换为每个实例的可读格式时发出警告 [英] Warning when trying to convert timestamp to readable format foreach instance while looping thorugh an array

查看:138
本文介绍了在循环通过数组尝试将时间戳转换为每个实例的可读格式时发出警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在遍历数组时尝试将时间戳转换为每个实例的可读格式时的警告。

Warning when trying to convert timestamp to readable format foreach instance while looping through an array.

<?php
    $json_feed = "http://localhost/sample/json/blog.json";
    $json = file_get_contents($json_feed);
    $obj = json_decode($json, true);
    $dateCreated = $array['post'].dateCreated;
    $date = date('m/d/Y H:i:s', $dateCreated);

    foreach($obj['post'] as $article_array){
        $url = $article_array['url'];
        $title = $article_array['title'];
        $category = $article_array['category'];
        $large_summary = $article_array['wp_post_content'];
        $date = $article_array[$date];

        $post = array(
            'post_title' => $title,
            'post_content' => $large_summary,
            'post_status' => 'publish',
            'post_type' => 'post',
            'comment_status' => 'closed',
            'dateCreated' => $date,
            'post_template' => 'content.php'
        );

        wp_insert_post ($post, $wp_error);
    }
?>




警告:date()期望参数2为整数,给定字符串在/Users/andrew/Desktop/newtest.php的第6行上

Warning: date() expects parameter 2 to be integer, string given in /Users/andrew/Desktop/newtest.php on line 6

任何帮助或建议将不胜感激。

Any help or suggestions will be greatly appreciated.

推荐答案

您需要启动变量

$date = date('m/d/Y H:i:s', strtotime($dateCreated))

这篇关于在循环通过数组尝试将时间戳转换为每个实例的可读格式时发出警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆