We use Google's Calendar as part of our church web page. It's easy to keep up to date and we don't have to install any special calendar software on our server. It even has an extremely sophisticated XML feed. OK, the feed is considerably shorter, if you tweak the call a bit, using Google's published parameters. You can use this feed in an RSS aggregator, informing your readers about what's happening in the near future. But this might not be exactly what you want.
This turns out to be relatively easy to do, if you know the trick, with a bit of PHP code. Let me say right off the top that I didn't come up with the PHP code myself, I got it from P.J. Cabrera, and it's available under what looks to be a pretty open license.
So I used Cabrera's script as the starting point to construct to scripts:
- First, an HTML web page, google_calendar_xml_parse_to_html.html, with an embedded PHP script which calls a Google calendar XML feed and parses it to form a web page that looks something like this.
- Second, a PHP script, google_calendar_xml_parse_to_rss.php, which parses the Google calendar XML feed to produce an RSS feed that looks like this.
The scripts are fully, possibly painfully, annotated, so you can see exactly what I did at every step. I'm not going to discuss them here, then, but you can add comments below, and I'll address them there.
Now you'd think I could just provide a link to each of the two
annotated pages, and you'd get the annotated pages. This turns out
not to be the case. The server will execute the PHP code on each
page, and then ship XML. Don't believe me? Load
up the web page
and/or the RSS
Feed and look at the source code. You won't find the PHP code,
perfectly formed XHTML or XML.
So I've put both scripts in this
tar file, parse_google_calendar.tar
(Sorry, my free web page server prohibits direct links to non-html pages, and doesn't allow ZIP files.)
Download the file, and you can extract both the html page, to create a calendar listing, and the php page, to create an RSS feed.
A few things to note:
- Don't forget to change the web addresses, as indicated. You'll also need your Google Calendar address.
- Note that the two files are linked, that is, the HTML page has a link to the PHP page, telling the world that the PHP is an RSS feed, and the PHP page links back to the HTML page, so that the reader can find your web site. You don't have to put in those links, of course.
- Of course, this only works if your server can handle PHP, but that doesn't seem to be all that much of a problem.
- Once the code is uploaded, you can check to be that the HTML page validates using the W3C validation service.
- Similarly, you can see if the PHP script creates a valid XML page by using the W3C Feed validation service.
Put all comments below.