tags:

views:

1106

answers:

5

Hello,

I have to produce RSS/Atom feed in various applications, and I want to know a good lib/class wich is able to produce both, and which already handle all common problems.

For example the one I used for year does not put the right format for date, so my feed is not well handled by several aggregators.

Thanks, Cédric

Update : Why I am looking for a lib? Because the one I used for years, which I had hacked a few, have a little problem. Maybe a specification is not correctly followed. http://stackoverflow.com/questions/182615/why-my-rss-feed-duplicate-some-entries

+4  A: 

Do you really need a library? Choose format and simply follow its specification to output valid XML.

Here is some tutorial to get started.

lubos hasko
+3  A: 

Hmmm, IMO, unless you want enclosures, both of these formats are easy enough to craft without any classes. E.g. for the RSS feeds of a website that I administrate, I simply wrote a small Smarty template, and it works pretty smoothly.

Rimas Kudelis
+15  A: 

The PHP Universal Feed Generator seems to be exactly what you're after - it has a simple, OO-based way of declaring a new feed and outputting it to your desired specification.

It also has built-in date format conversions as one of it's features.

Features:

  • Generates RSS 1.0, RSS 2.0 and ATOM 1.0 feeds
  • All feeds are are validated by feed validator.
  • Implements appropriate namespaces for different versions.
  • Automatically converts date formats.
  • Generates UUID for ATOM feeds.
  • Handles CDATA encoding for required tags.

Supported versions:

  • RSS 1.0 (which officially obsoleted RSS 0.90)
  • RSS 2.0 (which officially obsoleted RSS 0.91, 0.92, 0.93 and 0.94)
  • ATOM 1.0
ConroyP
And if you're interested in having the library generate W3C-standardized RSS1/2 and Atom feeds, I wrote a patch for it: http://sites.google.com/site/danchurchinc/software-patches
amphetamachine
+1  A: 

PHP Universal Feed Generator is a good answer. I had just to modify the code accordingly to a comment on the webpage to handle correcly french characters.

http://www.ajaxray.com/blog/2008/03/08/php-universal-feed-generator-supports-rss-10-rss-20-and-atom/#comment-341

Like Kereste says (1. June) FeedWrite makes problems with some none-english utf-8 characters like ä etc.. this is because xml only knows 5 entities (&,”,’,). So I changed line 298 in the source code into

$nodeText .= (in_array($tagName, $this->CDATAEncoding))? $tagContent : str_replace ( array ( ‘&’, ‘”‘, “‘”, ” ), array ( ‘&’ , ‘"’, ‘'’ , ‘<’ , ‘>’ ), $tagContent);

to avoiod converting charakters into wrong xml entities.

Cédric Girard
A: 

For non-english charsets take a look at the PHP function htmlentities: http://php.net/manual/en/function.htmlentities.php

I've just added to support croatian charset:

$nodeText .= (in_array($tagName, $this->CDATAEncoding))? $tagContent : htmlentities($tagContent, ENT_COMPAT, 'UTF-8');
Alex Sosic