我正在使用 php include(mandatory) 和 simplepie 来获取事件标题和开始日期,但它一直给我 2013 年 8 月 8 日的每个事件。我可以很好地看到这些事件。知道如何从中获取“何时”标签吗?如果我使用标签,我会得到错误。我不是 php 的专业人士,我现在已经无能为力了!
<?php
if ($_SERVER['QUERY_STRING']) {
parse_str($_SERVER['QUERY_STRING'], $arg);
} else {
$arg['feed'] = '';
$arg['count'] = '';
$arg['more'] = '';
$arg['nodiv'] = '';
}
if (!isset($arg['nodiv'])) $arg['nodiv']='false';
if ($arg['nodiv'] != 'true') {
?>
<div id="news_list">
<?php
}
include('simplepie.inc');
// Let's create a new SimplePie object
$feed = new SimplePie();
$feed = new SimplePie();
$feed->set_file($file);
$feed->enable_cache(false);
$feed->init();
$feed->handle_content_type();
// This is the feed we'll use
$feed->set_feed_url('http://www.google.com/calendar/feeds/aufdccetl%40gmail.com/public/full?max-results=2');
// Let's turn this off because we're just going to re-sort anyways, and there's no reason to waste CPU doing it twice.
$feed->enable_order_by_date(false);
// Initialize the feed so that we can use it.
$feed->init();
// Make sure the content is being served out to the browser properly.
$feed->handle_content_type();
// We'll use this for re-sorting the items based on the new date.
$temp = array();
foreach ($feed->get_items() as $item) {
// We want to grab the Google-namespaced <gd:when> tag.
$when = $item->get_item_tags('http://schemas.google.com/g/2005', 'when');
// Once we grab the tag, let's grab the startTime attribute
$date = $when[0]['attribs']['']['startTime'];
// Let's convert it all to UNIX timestamp. This will be used for sorting.
$sortDate = SimplePie_Misc::parse_date($date);
// Let's format it with date(). This will be the date we display.
$gCalDate = date('l, F j, Y', $sortDate);
// This is how each item will be displayed. We're adding it to the array we created earlier, and indexing it by the $sortDate.
$temp[$sortDate] = '<p> <div class="event_title"><a href=' . $feed->get_permalink(). '>' . $item->get_title() . '</a></div> <div class="event_date"> ' . $gCalDate . '</div> <br/></p>';
}
// Change this to krsort() to display with the furthest event first.
ksort($temp);
// Loop through the (now sorted) array, and display what we wanted.
foreach (array_slice($temp, 0, 3) as $paragraph) {
echo $paragraph;
}
?>
该脚本可以很好地获取事件标题和日期,它没有获取事件的公共 URL。而是向我展示了一个空白日历。关于如何通过 url 获取公共事件信息的任何想法?