在过去的四个小时里,我一直在研究如何解析xml并回显谷歌日历提要。我一开始使用本教程轻松完成了这一点,但遇到了命名空间问题,我可以轻松打印出事件的摘要和标题,但我无法打印出 startTime 和 endTime,因为他们在提要中使用<gd:when startTime>
等。我找到了 coreylib 并听到了很多关于它的简单性的赞美,但我仍然不知道如何做到这一点。
有人可以指出我的方向或给我一个从"完整"谷歌提要(http://www.google.com/calendar/feeds/developer-calendar@google.com/public/full - 示例提要)中检索一些事件的示例代码。即使它只是检索了事件的标题和开始时间,这也足以使用。
通常我会发布代码,但在这种情况下,我几乎没有代码,因为我被困住了那么糟糕哈哈。提前谢谢你!
$email = "yourEmail";
$url = "http://www.google.com/calendar/feeds/".$email."/public/full";
$xml = file_get_contents($url);
$feed = simplexml_load_string($xml);
$ns=$feed->getNameSpaces(true);
foreach ($feed->entry as $entry) {
$when=$entry->children($ns["gd"]);
$when_atr=$when->when[0]->attributes();
$start=$when_atr['startTime'];
$end=$when_atr['endTime'];
$title=$entry->title;
echo "<p>".$start." - ".$end." ".$title."</p>";
}
做了更多的搜索并找到了类似的东西,如果每个人都需要类似的东西,它就会很好地工作。呜呜!
根据您上面的内容,我可以对其进行一些修改以调整样式。
菲律宾比索
<?php
$email = "your public calendar address email";
$url = "http://www.google.com/calendar/feeds/".$email."/public/full";
$xml = file_get_contents($url);
$feed = simplexml_load_string($xml);
$ns=$feed->getNameSpaces(true);
foreach ($feed->entry as $entry) {
$when=$entry->children($ns["gd"]);
$when_atr=$when->when[0]->attributes();
$title=$entry->title;
echo "<div class='eventTitle'>".$title . "</div>";
$start = new DateTime($when_atr['startTime']);
echo "<div class='eventTime'>".$start->format('D F jS, g:ia') . " to ";
$end = new DateTime($when_atr['endTime']);
echo $end->format('g:ia')."</div>" . '<br />' ;
}
?>
CSS的
<style>
.eventTime {
color:#0CF;
}
.eventTitle {
color:#0FC;
}
</style>
以下资源很有帮助:
发布日期、日期和时间以及示例@Glavić。