21

I have to produce an RSS/Atom feed in various applications, and I want to know a good library or class which is able to produce both, and which already handles all common problems.

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

Update: Why I am looking for a library? Because the one I used for years, which I had hacked a few times, has a little problem. Maybe a specification is not being correctly followed.

Why does my RSS feed duplicate some entries?

Community
  • 1
  • 1
Cédric Girard
  • 3,358
  • 7
  • 37
  • 52

5 Answers5

28

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
  • 40,958
  • 16
  • 80
  • 86
  • 2
    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 Apr 06 '10 at 12:37
  • ajaxray.com is offline right now, but [the package may be downloaded via phpclasses.org](http://www.phpclasses.org/package/4427-PHP-Generate-feeds-in-RSS-1-0-2-0-an-Atom-formats.html). – feeela Oct 21 '11 at 10:42
  • @feela cheers, link in answer updated. – ConroyP Oct 24 '11 at 13:58
  • Unfortunately it does not work properly – Tom Smykowski Nov 10 '15 at 20:23
4

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
  • 24,752
  • 10
  • 56
  • 61
3

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
  • 555
  • 3
  • 12
3

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
  • 61
  • 3
1

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
  • 3,358
  • 7
  • 37
  • 52
  • 2
    If the class doesn't support the W3C format and has problems with UTF-8 it can't be good… – feeela Oct 21 '11 at 10:44