The best PHP lib/class to generate RSS/Atom [closed]

天涯浪子 提交于 2019-12-17 22:32:16

问题


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?


回答1:


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



回答2:


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

Here is some tutorial to get started.




回答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.




回答4:


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');



回答5:


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.



来源:https://stackoverflow.com/questions/182510/the-best-php-lib-class-to-generate-rss-atom

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