As several programmers work on inventing new kinds of aggregators, Phil Ringnalda takes note of something that isn't being discussed -- whether to use Atom, RSS 1.0, or RSS 2.0:

Not one of them says anything about having any real interest in the format used to deliver the feeds they consume. Why would they? That's a library function, parsing feeds and normalizing them into native data structures. It's the data that's interesting, not the format that you never see.

Working on a project that consumes all of these syndication formats, I'm getting an interesting perspective on the format debates.

The code doesn't care.

With the Magpie RSS library for PHP, once I have a feed item in an array, I can handle Atom date constructs, RSS 1.0's dc:date, and RSS 2.0's pubDate elements with a couple function calls:

$date = "";
$rss_2_date = $item['pubdate'];
$rss_1_date = $item['dc']['date'];
$atom_date = $item['issued'];
if ($atom_date != "") $date = parse_w3cdtf($atom_date);
if ($rss_1_date != "") $date = parse_w3cdtf($rss_1_date);
if ($rss_2_date != "") $date = strtotime($rss_2_date);
if ($date == "") $date = time();

The strtime method is part of PHP and parse_w3cdtf is part of Magpie. Both produce a Unix timestamp value.

An example script and output are available.


You can't imagine my disappointment at what the "get dates" in the title turned out to mean.

Sorry about that. This is the only kind of date compatibility I can speak about with authority.

Okay, I have to ask: what am I missing in the final two sentences? You say that you have a parse_w3cdtf function from MagpieRSS that parses the W3CDTF in dc:date, and if only you had a parse_w3cdtf function, you could parse the W3CDTF in Atom.

I have edited this weblog entry to hide my shame.

I think a better question is how did I miss that? Believe it or not, I searched the Web for W3C date handling PHP code and quit, disgusted I couldn't find any.

Btw when we all switch over to using PHP5 parse_w3cdtf will no longer be needed, just strtotime.

Thanks, I had swam through this mire a few weeks back for our Feed2JS service:

I had forked code for dates in item->dc:date versus item->pubDate
Oddly, I had found that Magpie was returning the Atom dates in item->dc:date

An uncleared issue I had with Magpie was that for feeds on a different web server port, Magpie lost track of the full root URL

Another loophole. There are 1.0 feeds with a dc:date element in the format:


such as mysql.rss

(e.g. a date stamp, not a date time stamp). A quick hack:


if ($rss_1_date != "") $date = parse_w3cdtf($rss_1_date);


if ($rss_1_date != "") $date = parse_w3cdtf($rss_1_date);
if (strlen($rss_1_date) == 10) $date = strtotime($rss_1_date);

Maybe there is something more elegant

I hate magpie rss a lot of bugs. I prefere to use Java script for Headlines news on my site

Have you noticed any incompatabilities for parse_w3cdtf with PHP 5?

I had Magpie wrking perfectly on a server with PHP 4, but on 5 it won't return a date-timestamp. I'm stumped and the only thing I can attribute it to is the different versions of PHP.

When i stunned while using the research people meant to makes unique post awesome. Superb pastime!


Popular Pages on This Site