组';今天';s事件';在单个日期标题下


Group 'Today's Events' under single Date Header?

我正在尝试解析一个谷歌日历,以便在我们的电视上显示"今日事件"。

由于一位朋友的帮助,我大部分时间都在那里,但我想看看是否有人能帮我走完剩下的路。

下面的代码生成包含所有信息的日历,但对于每个条目,它都显示日期。由于它们都是同一天,所以当我看到它时,这有点令人沮丧和困惑。我离程序员还差得很远,但我能理解一些事情。

如何将所有"今日"活动分组到一个日期标题下?

提前谢谢。

<?php
    $confirmed = 'http://schemas.google.com/g/2005#event.confirmed';
    $three_months_in_seconds = 60 * 60 * 24 * 28 * 3;
    $three_months_ago = date("Y-m-d'Th:i:s", time() - $three_months_in_seconds);
    $three_months_from_today = date("Y-m-d'Th:i:s", time() + $three_months_in_seconds);
    $params = "?orderby=starttime&start-min=" . $three_months_ago . "&start-max=" . $three_months_from_today;
//$params = "?orderby=starttime&start-min=2012-12-01T05:48:47&start-max=2013-05-07T05:48:47&sortorder=a&singleevents=true&futureevents=true";
$params = "?orderby=starttime&sortorder=a&singleevents=true&futureevents=true";
    $feed = "https://www.google.com/calendar/feeds/REDACTED%40gmail.com/private-REDACTED/full".$params;
    $doc = new DOMDocument();
     if (!$doc->load( $feed )) echo 'failed to load';
    $entries = $doc->getElementsByTagName( "entry" );
    foreach ( $entries as $entry ) {
        $status = $entry->getElementsByTagName( "eventStatus" );
        $eventStatus = $status->item(0)->getAttributeNode("value")->value;
        if ($eventStatus == $confirmed) {
            $titles = $entry->getElementsByTagName( "title" );
            $title = $titles->item(0)->nodeValue;
            $times = $entry->getElementsByTagName( "when" );
            $startTime = $times->item(0)->getAttributeNode("startTime")->value;
            $when = date( "D M j, Y", strtotime( $startTime ) );
            $time = date("g:i A",strtotime($startTime));

            $places = $entry->getElementsByTagName( "where" );
            $where = $places->item(0)->getAttributeNode("valueString")->value;
            print "<div class='row when'>$when</div>";
            echo "<div class='row event'><span class='time'>$time</span><span class='title'>$title</span><span class='where'>$where</span></div>";
//            print $where . "'n";
            print "'n";
        }
    }
?>

有一个答案:

只需更改一下:

print "<div class='row when'>$when</div>";

到此:

if ($old_when!=$when) print "<div class='row when'>$when</div>"; $old_when=$when;

并添加

$old_when = null;

在每个之前