我正在尝试创建社交时间线。我从某些地方吸食饲料,所以我有我做过的事情的时间表。我遇到的问题是Google阅读器共享项目。使用simplexml_load_file()解析原子提要时遇到困难,无法获得属性
我想获得我分享包含在<entry gr:crawl-timestamp-msec="1269088723811">
中的项目的时间尝试使用$date = $xml->entry[$i]->link->attributes()->gr:crawl-timestamp-msec;
获取元素失败,原因是:after gr导致PHP错误。我可以弄清楚如何获得元素,所以以为我会使用下面的代码更改名称,但它引发以下错误
Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "<?xml version="1.0"?><feed xmlns:idx="urn:atom-extension:indexing" xmlns:media="http://search.yahoo.com/mrss/" xmlns
<?php
$get_feed = file_get_contents('http://www.google.com/reader/public/atom/user/03120403612393553979/state/com.google/broadcast');
$old = "gr:crawl-timestamp-msec";
$new = "timestamp";
$xml_file = str_replace($old, $new, $get_feed);
$xml = simplexml_load_file($xml_file);
$i = 0;
foreach ($xml->entry as $value)
{
$id = $xml->entry[$i]->id;
$date = date('Y-m-d H:i:s', strtotime($xml->entry[$i]->attributes()->timestamp));
$text = $xml->entry[$i]->title;
$link = $xml->entry[$i]->link->attributes()->href;
$source = "googleshared";
echo "date = $date<br />";
$sql="INSERT IGNORE INTO timeline (id,date,text,link, source) VALUES ('$id', '$date', '$text', '$link', '$source')";
mysql_query($sql);
$i++;
}`
有人能指出我在正确的方向吧。
干杯
克雷格
嗨克里斯, 感谢您的及时回复。知道这是与IBM网站的命名空间相关的东西,但无法弄清楚。我已替换您所说的内容,但会抛出另一个错误 '注意:使用未定义的常量时间戳记 - 假设'时间戳记'在第52行的/Users/craigward/Dropbox/Websites/wip/cron/get_feed_data.php中 :使用未定义的常量毫秒 - 在第52行的/Users/craigward/Dropbox/Websites/wip/cron/get_feed_data.php中假定'msec' date = 0' – 2010-03-20 21:53:42
@Craig使用Chris的答案和我的组合(使用卷曲括号和引号),它应该工作。 – 2010-03-20 22:07:35
和+1 - 我知道还有更多它:) – 2010-03-20 22:08:00