这是一个很难描述的内容。所以我使用Facebook图表在网站上显示我的页面facebook / twitter(通过Facebook)的视图。一切都很好,除了我试图让created_time成为更好的格式。我已经测试了created_time的pout以确保它有效,就像这样......
$string = 2012-02-06T19:38:35+0000
但是,当我尝试动态传递$ data-> created_time时;它不喜欢它得到的东西,所以它说日期是1970年1月1日。我知道它可能会让某些东西变得难以理解,但我无法看到它是什么来诊断它。 :/
以下是所有代码......
<?php
$info = json_decode(file_get_contents('https://graph.facebook.com/210849652406/feed/?access_token=[ACCESS_TOKEN]&limit=20'));
$string = $info->data->created_time;
$pattern = '/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\+(\d{4})/i';
$replacement = '$3-$2-$1 $4:$5:$6';
$new_time = preg_replace($pattern, $replacement, $string);
$dTime = strtotime($new_time);
//format the date / time into something human readable
//if you want it formatted differently look up the php date function
$myTime=date("M d Y h:ia",$dTime);
if ($info) {
foreach ($info->data as $obj) {
if ($obj->application->name =='Twitter') {
echo "<div class=\"ca-item\"><div class=\"ca-item-main-twitter\">";
echo "<div><span class=\time\><a href=\"https://twitter.com/#!/ouhsd\">@OUHSD--", $myTime,"</a></span>";
echo "<span class=\"content\">", $obj->message, "</span></div>" ;
echo "<div class=\"us\"></div>";
echo "</div></div>";
}
}
}
?>
答案 0 :(得分:0)
提示:为了解决问题,请不要在饥饿时推迟午餐。午餐后,当你没有挨饿而不太急于解决问题时,你可能会解决这个问题。答案比我想象的更简单!
解决方案......
<?php
$info = json_decode(file_get_contents('https://graph.facebook.com/210849652406/feed/?access_token=305397012843053|0Lge1zfZW1kE77tnJ0gbmcGLNuo&limit=20'));
if ($info) {
foreach ($info->data as $obj) {
$dTime = strtotime($obj->created_time);
//format the date / time into something human readable
//if you want it formatted differently look up the php date function
$myTime=date("M d Y h:ia",$dTime);
if ($obj->application->name =='Twitter') {
echo "<div class=\"ca-item\"><div class=\"ca-item-main-twitter\">";
echo "<div><span class=\time\><a href=\"https://twitter.com/#!/ouhsd\">@OUHSD--", $myTime,"</a></span>";
echo "<span class=\"content\">", $obj->message, "</span></div>" ;
echo "<div class=\"us\"></div>";
echo "</div></div>";
}
}
}
?>
我试图在调用它之前修复时间,我没有必要