Parsing google calendar XML feed

故事扮演 提交于 2019-12-05 09:02:42
Kenneth Reitz

I highly recommend using this library: https://github.com/collegeman/coreylib. It'll make everything from start to finish mind-numbingly easy.

There are of course several ways to parse the XML. Display Google Calendar events on your PHP Web site with XPath (see "Parsing the Google Calendar feed with PHP") and Integrate your PHP application with Google Calendar are two comprehensive resources with sample code and more.

Personally, I used the following approach:

$doc = new DOMDocument(); 
$doc->load('http://my.feed.com');
$entries = $doc->getElementsByTagName("entry"); 
foreach ( $entries as $entry ) { 
  $titles = $entry->getElementsByTagName("title"); 
  $title = $titles->item(0)->nodeValue;

  $times = $entry->getElementsByTagName("when"); 
  $startTime = $times->item(0)->getAttributeNode("startTime")->value;
  $when = date("l jS \o\f F Y - h:i A", strtotime($startTime));
  // ...
}

In order to access the georss namespace etc. have a look at (and its output)

foreach ($doc->getElementsByTagNameNS('*', '*') as $element) {
  echo 'localName: ', $element->localName, ', prefix: ', $element->prefix, "\n";
}

You can use the Zend GData library to parse Google web services (including the calendar). It's easier than trying to use the XML code manually. There is a tutorial that shows you how to do this here.

Full Calendar was MUCH easier than Coreylib. Coreylib wasn't drop dead simple, although I'm sure it is very powerful.

I had FullCalendar running in 5 minutes. http://arshaw.com/fullcalendar/docs/google_calendar/

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!