PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM)

by admin on March 8, 2008

It’s been a while since I’ve planned on developing a RSS writer that fulfills most my needs by supporting the various feed formats. Although the necessity was the prime force behind it, a discussion with Hasin and Emran has put the actual fire in. We were discussing about what can be added next in the Orchid – “PHP framework for the rest of us” and suddenly it hit me. At last, it’s finally complete and I’ve named it “PHP Universal Feed Generator“, as it generates both ATOM and RSS feeds.

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

Download:

Features:

  • Generates RSS 1.0, RSS 2.0 and ATOM 1.0 feeds
  • All feeds are are validated by feed validator.
  • Supports all possible feed elements.
  • Simple and easy to define channel and feed items
  • Implements appropriate namespaces for different versions.
  • Automatically converts date formats.
  • Generates UUID for ATOM feeds.
  • Enables usage of subtags and attributes. (example: image and encloser tags)
  • Completely Object oriented in PHP5 class structure.
  • Handles CDATA encoding for required tags.
  • Nearly same code for generating all kinds of feed

A minimum example

It’s a minimum example of using this class. I am generating a RSS 2.0 feed from retrieved data from a MySQL database. There are more examples in the download package for different versions.

<?php
  // This is a minimum example of using the Universal Feed Generator Class
  include("FeedWriter.php");

  //Creating an instance of FeedWriter class. 
  $TestFeed = new FeedWriter(RSS2);

  //Setting the channel elements
  //Use wrapper functions for common channel elements
  $TestFeed->setTitle('Testing & Checking the RSS writer class');
  $TestFeed->setLink('http://www.ajaxray.com/projects/rss');
  $TestFeed->setDescription('This is test of creating a RSS 2.0 feed Universal Feed Writer');

  //Image title and link must match with the 'title' and 'link' channel elements for valid RSS 2.0
  $TestFeed->setImage('Testing the RSS writer class','http://www.ajaxray.com/projects/rss','http://www.rightbrainsolution.com/images/logo.gif');

    //Retriving informations from database
    mysql_connect("server", "mysql_user", "mysql_password");
    mysql_select_db("my_database");

$result = mysql_query(“Your query here”);

 

    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
        //Create an empty FeedItem
        $newItem = $TestFeed->createNewItem();

        //Add elements to the feed item    
        $newItem->setTitle($row['title']);
        $newItem->setLink($row['link']);
        $newItem->setDate($row['create_date']);
        $newItem->setDescription($row['description']);

        //Now add the feed item
        $TestFeed->addItem($newItem);
    }

  //OK. Everything is done. Now genarate the feed.
  $TestFeed->genarateFeed();
?>

Shhhh….a universal feed reader is on the way ;)

194 comments

[...] : The PHP Universal Feed Generator class, for which I wrote this function is released. Share and Enjoy: These icons link to social [...]

by PHP UUID generator function | ajaXray on March 8, 2008 at 2:00 pm. Reply #

Hello there.

Did a quick look and I have a few comments:
- It should be “generateFeed” and not “genarateFeed”
- The constants would be better as class constants imho
- The __autoload has nothing to do there and will be annoying for people using your code (they’ll have to remove it)
- (Almost) everything private should be protected instead to allow for inheritance
- What is the license? It’s not written anywhere
- I’m not very fan of all these concatenation, 3 template files (1 for each type of feed) could be clearer and less bug-prone

Good work.

by Loïc Hoguin on March 9, 2008 at 8:21 am. Reply #

Hey there,

Just wanted to let you know that you should test your site in Safari, because the whole main body container is flipping to the left out of alignment with the header container. Its also noticeable on Firefox, although its not nearly as bad as Safari.

Great post by the way.

by Jake Rutter on March 10, 2008 at 7:06 am. Reply #

I do not find if this is not the best code, the main thing is that it works! Thank you very much Loic when you do some developments let us know to check if you create code as you criticise

by dax on March 10, 2008 at 7:32 am. Reply #

[...] estos casos en Ajax Ray crearon un código php que utilizando simplemente las clases correctas podemos generar un feed valido prácticamente desde [...]

by Generar un feed con PHP | Kabytes on March 10, 2008 at 7:42 am. Reply #

@Loïc Hoguin:
Thanks a lot for your suggestion. I’ll modify it soon as your comment.
When the createNewItem() function is called, the __autoload() function loads the FeedItem class from FeedItem.php file.
Thanks you again.

by admin on March 10, 2008 at 8:03 am. Reply #

@Jake Rutter:
Thanx for you comment.
I’ve tested the site in safari 3.0.4 and no problem found there. Can you plz tell me about your Safari version?

by admin on March 10, 2008 at 8:05 am. Reply #

great post. i guess this will solve most people’s need of a good rss writer class. thanks for mentioning me :)

by Md Emran Hasan on March 10, 2008 at 8:44 am. Reply #

Specially happy to make it part of Orchid

by H2 on March 10, 2008 at 9:10 am. Reply #

Yes, the __autoload is there for loading the item class, but what I was trying to point out was that if I include your feed generator while already having an __autoload in my project, it’ll die because the __autoload function already exist. So I would have to remove that part.

But that’s just a small annoyance, don’t worry about it too much. :)

Have fun polishing it!

by Loïc Hoguin on March 10, 2008 at 9:15 am. Reply #

To do an autoloading behavior that plays well with others, you should use spl_autoload_register() (http://www.php.net/spl-autoload-register). With that, you can register any valid PHP callback you wish to serve as your autoloader.

by Travis Swicegood on March 10, 2008 at 9:34 am. Reply #

[...] [view original post] [source: Delicious] Previously – WordPress Upgrade Preparation Checklist : The Blog Herald Next – [...]

by Metaholic » PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM) on March 10, 2008 at 10:18 am. Reply #

simplepie.org is a great universal feed reader, btw

by brandon on March 10, 2008 at 10:59 am. Reply #

[...] PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM) (tags: php) [...]

by Skylog » Blog Archive » links for 2008-03-11 on March 10, 2008 at 11:17 pm. Reply #

This worked fine for me. Cheers mate.

by Welcome to Paradise on March 10, 2008 at 11:43 pm. Reply #

[...] PHP Universal Feed Generator [...]

by Librería PHP para crear Feeds « Think Free - Linux.Php.Java.ME.Movies on March 11, 2008 at 9:49 am. Reply #

[...] PHP feed generator. Librería en PHP para dotar de feeds RSS o ATOM a tus proyectos web. Visto en Sentido Web. [...]

by 7 Fast Links (y X) : Un lugar en el mundo… on March 11, 2008 at 1:28 pm. Reply #

[...] PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM) | ajaXray – Haven't looked to see if this is any good yet. Having something like this is good from PHP though. Tags: atom feed php rss [...]

by Links for Mon 10 Mar 2008 through Tue 11 Mar 2008 - Joseph Scott’s Blog on March 12, 2008 at 11:58 am. Reply #

[...] PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM) | ajaXray (tags: php generator feed opensource programming) [...]

by links for 2008-03-12 « toonz on March 12, 2008 at 4:21 pm. Reply #

[...] PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM) PHP Feed generator, 還沒用過, 不過看過範例, 覺得頗好用的, 先記下來。 話說我目前產生 RSS Feed 是用 template 的方式, 還滿方便、快速的。 [...]

by [網摘] 20080314 « Oceanic | 人生海海 on March 14, 2008 at 3:38 am. Reply #

Thanks a lot for your code !
But where is the .xml generated ? (I’m beginning …)

Thank you !

by Romain on March 16, 2008 at 7:23 pm. Reply #

@Romain:
Hi friend,
Thanks for your comment.
There is no need to have a separate file with .xml extension. When you call the generateFeed() function, it sets the header Content-type as “text/xml”. So, the browser handle the output as an XML file.

by admin on March 16, 2008 at 11:15 pm. Reply #

[...] php universal feed generator [...]

by Tims Blog » Blog Archive » Business. Not Family on March 17, 2008 at 7:35 pm. Reply #

[...] PHP Universal Feed Generator es una librería para generación de feeds en varios formatos. [...]

by Propiedad Privada » Blog Archive » Enlaces interesantes PHP on March 18, 2008 at 6:14 am. Reply #

Anis vai,

I’ve tested the examples and found the following error

http://localhost/feedwriter/example_minimum.php

Fatal error: Call to a member function query() on a non-object in C:apachefriendsxampphtdocsfeedwriterexample_minimum.php on line 18

Would you please check out this.

By the way, all the things are appreciatable. But I’ve two suggestions for you.
1) FeedWriter.php: In function startItem (line 398) you’ve used die. But anyone may want to handle exception according to his/her necessities. So, throw new Exception() should be used here.
2) FeedWriter.php: You’ve used echo in several functions to generate Feed. But I think it would be better if you assign all the echos in a string and return the string to the caller. As for example, anyone can write echo $TestFeed->genarateFeed(); (See example_rss1.php line 44).

Thanks.

by Mohammad Jahedur Rahman on March 19, 2008 at 9:42 pm. Reply #

@Mohammad Jahedur Rahman :
Jahid vai,
Thanks for your comment.
Here the “$db->query()” is just an example of using.
There is no database connection and no $db class in this script.
You have to re-write this data collecting portion yourself as your database.

I’ll keep in mind your suggestions and try to implement in next version.

by admin on March 20, 2008 at 12:30 am. Reply #

[...] PHP Universal Feed Generator Librería que nos permite añadir feeds en varios formatos en nuestras aplicaciones. [...]

by Scripts for 2008-03-20 | CalinSoft on March 20, 2008 at 8:16 am. Reply #

it gots some problems with chinese character.
SO I modify some source code.
In Line 298

htmlentities($tagContent);
switch
htmlentities($tagContent, ENT_COMPAT, ‘utf-8′);

In Line 82
header(“Content-type: text/xml”);
switch to
header(“Content-type: text/xml; charset=UTF-8″);

by johnpupu on March 26, 2008 at 7:42 am. Reply #

It got some problems with chinese character.
so I modify some source code.
at Line 298

change htmlentities($tagContent);
to
htmlentities($tagContent, ENT_COMPAT, ‘utf-8′);

at Line 82
change
header(”Content-type: text/xml”);
to
header(”Content-type: text/xml; charset=UTF-8″);

that’s it

by johnpupu on March 26, 2008 at 7:56 am. Reply #

how do I link it to the mysql DB? I cannot make sense about that? How do I pass the user/pass and select with dB/tables to query? Could you please explain that a lil bit more?
Thanks! great script!

by Sergio on March 27, 2008 at 8:02 am. Reply #

@sergio:
Hi friend,
U and some of others were confused at this portion.
So, I’ve changed it.
Hope it will be easier now to understand how to collect informations from db and use with this class.

Thanks a lot.

by admin on April 2, 2008 at 1:52 pm. Reply #

[...] PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM) | ajaXray [...]

by RSS Feeds in PHP « Abner’s Postgraduate Days on April 15, 2008 at 8:39 am. Reply #

it can run in php4 ??!!
because run in php5 is ok
but php5 have an error


Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or ‘}’ in /www/history/FeedWriter/FeedWriter.php on line 20

by dowdot on April 22, 2008 at 3:08 am. Reply #

[...] the PHP Universal Feed Generator, I’ve written the PHP Universal Feed Parser for Orchid Framework.  It’s a RSS and [...]

by PHP Universal Feed Parser - lightweight PHP class for parsing RSS and ATOM feeds. | ajaXray on May 2, 2008 at 9:49 am. Reply #

[...] Feedwriter / PHP [...]

by Milestone 01 - 70+ High-End Components for Web Designers and Developers : DevKick Blog on May 13, 2008 at 2:07 pm. Reply #

For knowledge thanking I do

by jenerator on May 26, 2008 at 3:02 pm. Reply #

[...] loro volta generati a partire da una base di dati. In questo caso ci viene in contro l’ottimo PHP Universal Feed Generator (che nome pomposo!): l’esempio d’uso presente nella pagina che ho linkato la dice lunga [...]

by Generare Feed RSS da una base di dati o da una qualsiasi pagine sul web -- viklog on May 29, 2008 at 7:02 am. Reply #

[...] PHP Universal Feed Generator [...]

by 30 Useful PHP Classes and Components « PHP::Impact ( [str blog] ) on May 29, 2008 at 3:40 pm. Reply #

Great idea! I got here after this class was listed on a post at PHP::Impact. I look forward to working with this class in the future.

by David Dashifen Kees on May 30, 2008 at 9:19 am. Reply #

[...] PHP Universal Feed Generator vous permet de générer vos Feed RSS facilement [...]

by PHP … ^^ | PHP-Engineering's Blog on June 1, 2008 at 8:26 am. Reply #

how do I link it to the mysql DB? I cannot make sense about that? How do I pass the user/pass and select with dB/tables to query

by define on June 1, 2008 at 12:24 pm. Reply #

it gots some problems with chinese character.
SO I modify some source code.
In Line 298

by Kereste on June 1, 2008 at 12:25 pm. Reply #

Thanks for your comment.
Here the “$db->query()” is just an example of using

by jenerator on June 1, 2008 at 12:26 pm. Reply #

[...] PHP Universal Feed Generator [...]

by 30 componentes y clases PHP muy útiles | aNieto2K on June 1, 2008 at 11:43 pm. Reply #

[...] PHP Universal Feed Generator [...]

by Recopilacion de componentes y clases PHP | Pboza on June 2, 2008 at 12:40 am. Reply #

[...] PHP Universal Feed Generator [...]

by 30 clases y componentes útiles para PHP on June 3, 2008 at 7:55 am. Reply #

[...] PHP Universal Feed Generator [...]

by 30 componentes y clases PHP muy útiles » Ricotero's Blog on June 3, 2008 at 7:59 pm. Reply #

[...] شده منفجر بشی از خوشی؟ بترکی؟ سرتاپات درد بگیره؟ اینو ببین: (لینک) [...]

by روزانه ها » Blog Archive » انفجار نور Ú©Ù‡ میگن اینه! on June 6, 2008 at 11:18 am. Reply #

[...] به کمک این کلاس بسیار خوب php، که اسم بلند و برازنده ی PHP Universal Feed Generator رو داره، حالا [...]

by کمانگیر » Ùˆ اینک: خوراک دیدیش - مشترک داغ ترین های وبلاگستان شوید! on June 6, 2008 at 12:14 pm. Reply #

[...] PHP Universal Feed Generator es una clase escrita en PHP 5 que permite crear Feeds en formato RSS 2.0, RSS 1.0 y Atom 1.0 de forma sencilla y cumpliendo los estándar de los Feeds. [...]

by PHP Feed Generator » unijimpe on June 17, 2008 at 9:46 pm. Reply #

What is the license? It’s kinda hard to evaluate if we should use this or not without knowing…

by Rob on June 26, 2008 at 3:23 pm. Reply #

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.

by kbraun on July 5, 2008 at 9:36 am. Reply #

Hello.
I had a problem with feedwriter, normally only special char-languagues may suffer it but solved easily

Line 289, function makeNode:
$nodeText .= (in_array($tagName, $this->CDATAEncoding))? $tagContent : htmlentities($tagContent);

Items titles doesnt have CDATA so it always pass the htmlentities function.
Well, then the titles always shows the &code; char system, but in xml, specially in rss, i think that is better to use the numer char system, for example í for í, #243; for ó (there are some functions to made this in htmlentities php.net manual
I think that the CDATA encodings must be always utf8 char type (with the encoding of document to utf8).
For fix that, you must replace there the htmlentities of l 289 function by the one that you use for convert to xml char types.

Sorry for my bad english. Bye.

by Nacho on July 8, 2008 at 7:33 am. Reply #

Hello. I think you are eactly thinking like Sukrat. I really loved the post.

by professional on July 18, 2008 at 7:26 pm. Reply #

[...] PHP Universal Feed Generator [...]

by TheDaVis Blog — 30 componentes PHP muy útiles on July 26, 2008 at 4:48 am. Reply #

Where I can see an example? Thanks

by hmongasia on August 15, 2008 at 11:54 pm. Reply #

[...] PHP Universal Feed Generator [...]

by RazibMiah » 30 Useful PHP Classes and Components on September 5, 2008 at 7:03 pm. Reply #

RSS 2.0 feed with PHP
http://usedauto.com.ua/

by Rusl on October 2, 2008 at 1:00 pm. Reply #

Thanks

by New Php on November 5, 2008 at 11:30 pm. Reply #

[...] PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM) | Let’s explore the web tech… FeedWriter.phpの解説: [...]

by PHPでフィードを発行するライブラリ「feedcreator」 at /* Think idea */ on November 6, 2008 at 2:02 pm. Reply #

Thank You. Good work i wish

by Boyabat Gazetesi on November 7, 2008 at 5:04 pm. Reply #

Info for the Thank You.

by Tugla on November 7, 2008 at 5:05 pm. Reply #

Lookin’ good, thanks a lot!

by Jojo on November 9, 2008 at 3:26 am. Reply #

First off, LOVE THE SCRIPT. Nice simple and works great for most all applications I would need it for, so an big THANK YOU!

I am having an issue though, I am trying to use this for an Itunes podcast. Here is the issue I am having. I tried just adding xmlns:itunes=”http://www.itunes.com/dtds/podcast-1.0.dtd” to the RSS2 feed and keep my type as RSS2. I also tried going through and creating a new ITUNES class copying the RSS2 class and adding xmlns:itunes=”http://www.itunes.com/dtds/podcast-1.0.dtd” but then removing it from the RSS2 class. When I do that (either option) it inserts the closing tags but without the backslash so technically they are all opening tags.

Any suggestions?

by Rammy on November 23, 2008 at 11:54 am. Reply #

[...] PHP Universal Feed Generator [...]

by 30 Useful PHP Classes and Components « Er. Krushna Chandra Muni on November 24, 2008 at 10:13 pm. Reply #

Thanks

by vodcax on November 30, 2008 at 8:49 am. Reply #

[...] PHP Universal Feed Generator es una librería para generación de feeds en varios formatos. [...]

by Interesante links para PHP « Amigos de lo Ajeno on December 8, 2008 at 5:49 pm. Reply #

Nice :) Thanks for sharing :)

by Nurul on January 11, 2009 at 3:59 pm. Reply #

Hi,

Thank you , i search and find your code is more useful than other codes for generate rss1,rss2,atom.

by ali on January 14, 2009 at 4:53 pm. Reply #

[...] Feed Writer, Generador RSS en PHP 5 Universal Feed Writer es un excelente generador RSS desarrollado por Anis uddin Ahmad, en php 5 y con una estructura [...]

by Univarsel Feed Writer, Generador RSS en PHP 5 « sobre peachep y eso de la internet on January 16, 2009 at 6:32 pm. Reply #

Thanks a lot by this code… really I’ll use this on my site.

Best Regards.

by Praia do Forte - Bahia on January 22, 2009 at 3:11 am. Reply #

[...] PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM)PHP Feed generator, 還沒用過, 不過看過範例, 覺得頗好用的, 先記下來。 話說我目前產生 RSS Feed 是用 template 的方式, 還滿方便、快速的。 [...]

by [網摘] March 14th 2008 - My Habari on January 29, 2009 at 10:35 am. Reply #

[...] bazý arkadaþlar oturmuþ rss 1.0 , rss 2.0 ve atom destekli bir feed generator (oluþturucu/üretici) hazýrlamýþlar. Kullanýmý da gayet basit.Zaten örnek olmasý açýsýndan küçük bir kod parçasý da vermiþler. [...]

by Php ile Kolay Rss ve Atom Feed Oluþturmak - webmasterci.com Türk Webmaster Forumu on February 9, 2009 at 1:40 am. Reply #

[...] web: http://www.ajaxray.com/blog/2…20-and-atom/ [...]

by PHP Universal Feed Generator | sastgroup.com on February 20, 2009 at 4:38 pm. Reply #

Thank you for developing feed generator! I used it to create a feed from items in a MySQL database and I am getting a couple of errors. 1) multiple items have the same value for link. 2) a problem with my date format. I see these when I run the feed (http://www.sph.umich.edu/scr/feedwriter/events_rss.php) through a validator (http://feedvalidator.org). Can you help?

by Patty Bradley-Diehl on February 27, 2009 at 12:53 am. Reply #

[...] 一些關於rss的東西 RSS 2.0 Specification PHP 產生 RSS/ATOM pubDate/created 所需格式 PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM) [...]

by Life["Breathing"] » rss note on March 5, 2009 at 1:45 pm. Reply #

Thanks a bunch, I’ve just used this for creating a custom Atom feed!

by Chris Longbottom on March 7, 2009 at 12:13 am. Reply #

[...] searching for existing PHP scripts to accomplish this, and came across Anis uddin Ahmad’s Universal Feed Writer classes. They can be used to create RSS1, RSS2 and ATOM feeds. I extended his classes so that they [...]

by Creating iTunes Feeds with PHP • Netmojo Systems on March 7, 2009 at 2:13 am. Reply #

Hello,
Great class! I am using it with SimplePie to merge some feeds. Is it possible to add more than one category to an item? Actually only one is added, even if I use a “foreach” loop…

Thank you for the answer!

by M. on March 25, 2009 at 10:22 pm. Reply #

http://www.phpclasses.org is a bletcherous quasi-malware site. And your own link for it is 404. There must be a better way for you to host this.

by Lucas Gonze on April 3, 2009 at 6:09 am. Reply #

Are there any instructions on how to use this RSS Generator? Every time I try it I get a blank page. When I run the Feed Validator I get the following:
Sorry
This feed does not validate.

line 1, column 0: XML parsing error: :1:0: no element found [help]

In addition, interoperability with the widest range of feed readers could be improved by implementing the following recommendation.

Feeds should not be served with the “text/html” media type [help]

Source: http://beta.kavon.com/KAVONNewsCenter/RSS/FeedWriter/example_rss2.php

Any help would be greatly appreciated.

Thanks,
John Novak

by John Novak on April 29, 2009 at 9:34 pm. Reply #

One of the problems I got was the following:
Use of undefined constant DATE_RSS – assumed ‘DATE_RSS’

I am also getting 3 blank lines at the beginning of the xml code which is causing an error.

Any ideas?

Thanks,
John Novak

by John Novak on April 30, 2009 at 9:29 am. Reply #

[...] ?????? RSS Feed ? PHP Class. ???? ? [...]

by ????? » PHP Universal Feed Generator on April 30, 2009 at 9:56 pm. Reply #

[...] ?????? RSS Feed ? PHP Class. ???? ? [...]

by ????? (Beta) » PHP Universal Feed Generator on April 30, 2009 at 10:10 pm. Reply #

Thank you…

by Kampanya on May 15, 2009 at 5:54 am. Reply #

Lookin’ good, thank you

by reklam on May 15, 2009 at 5:58 am. Reply #

Thank you very much good work for information

by reklam on May 15, 2009 at 5:59 am. Reply #

[...] up with combineFeed.php (click for source)!  Its a pretty simple script that uses SimplePie and FeedWriter to pull in a bunch of RSS feeds, combine and sort them by date, then write them back out as a RSS [...]

by Combining Twitter Feeds (or any RSS feeds for that matter!) | Octane and Caffeine on May 20, 2009 at 7:43 am. Reply #

Neat internet site. Will definitely visit soon.

by Peeprirwers on May 21, 2009 at 2:15 am. Reply #

[...] RSS – FeedWriter [...]

by Which open source frameworks, libraries and IDEs I use « Web coder blog on June 22, 2009 at 12:36 pm. Reply #

Thanks !

Very useful !

by Guillaume on June 29, 2009 at 1:48 pm. Reply #

But polish chars doesn’t work…

What i have to do if I want use polish chars ?

I have this error:
XML Parsing Error: junk after document element
Location: http://www.example.com/feed/
Line Number 3, Column 1:http://www.example.com/feed
^

by dawid on July 5, 2009 at 8:03 pm. Reply #

hi

who is the best software for rss feeds creating ?

thanks

nikola

by Nikola on July 26, 2009 at 3:09 am. Reply #

Hi thanks…

by tugla on August 10, 2009 at 4:48 am. Reply #

[...] PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM) – Let’s explore the web technolo… [...]

by ??????????? | ????? on August 24, 2009 at 10:08 am. Reply #

Great post. Thanks!

by Goran on August 28, 2009 at 3:21 am. Reply #

very nice great post

by aöf kay?t ba?vuru on September 11, 2009 at 4:03 pm. Reply #

It seems not work for Chinese word.

by Henry on September 26, 2009 at 3:20 am. Reply #

how use it ?

by realturk on October 1, 2009 at 9:11 pm. Reply #

im just a beginner in this….but just wanna say i found this feed generator @ the web. Ist also easy to use and cool stuff if ure not into this. Just copy the rss link into the creator and choose your design…

by Feed Beginner on October 2, 2009 at 10:40 pm. Reply #

nice, but 2 small things i noticed fast…

1. pls return your code as a string. so we can echo it ourselves or easily write it to a file. now everything is echoed by the functions
2. i think you meant to use the name of the function “generateFeed” not “genarateFeed” for the FeedWriter object

by somebody on October 22, 2009 at 12:07 am. Reply #

Where to get a PHP script which crawling all html pages on site and auto writing all new content into RSS?

Thanks.

by Alex on October 22, 2009 at 10:27 am. Reply #

Thanks, great rss feed generator :)

http://socialenginemechanic.com/groups/feed.php

by clare on October 29, 2009 at 7:55 am. Reply #

Hi
Who of you are having problem with Non ASCII characters, can try this suggestion from ‘Nacho’.

See the line 289:
$nodeText .= (in_array($tagName, $this->CDATAEncoding))? $tagContent : htmlentities($tagContent);

Here the htmlentities function is being used with default options. You can see the php manual for list of charsets that are supported by htmlentities and can use your one.

by Anis Ahmad on November 6, 2009 at 4:55 pm. Reply #

how use it ?

by bayramören on November 11, 2009 at 11:07 pm. Reply #

Thanks for greate tools.
to use this class with none ascii characters change htmlentities to htmlspecialchars

by AlexeyBalin on November 21, 2009 at 4:55 pm. Reply #

@ Anis Ahmad: That would be line 298 :) . Thanks for pointing it out.

Just changing the:
htmlentities($tagContent); to htmlentities($tagContent, ENT_QUOTES, 'UTF-8'); will take care of all languages.

Cheers,
m^e

by miCRoSCoPiC^eaRthLinG on November 25, 2009 at 2:21 pm. Reply #

hm,
validator offeres me an improvement to encrease compatibility in rss2

Missing atom:link with rel=”self”

how to achieve this?

by zollko on November 27, 2009 at 11:10 pm. Reply #

Question here… I’m using your class in a project of mine and all’s working perfectly. Feeds are delivered from domain.com/feed/…

Now my question is, how do I detect (using PHP) which kind of feed is being requested – Atom, RSS or RSS2 ? As of now, I’m manually setting RSS2 while instantiating FeedWriter.

Googled for it but couldn’t come up with anything concrete.

Thanks,
m^e

by miCRoSCoPiC^eaRthLinG on November 28, 2009 at 11:00 pm. Reply #

Well, you could have a $_GET[] parameter and whichever the value is, generate a feed writer.

by Tristan Seifert on November 29, 2009 at 10:49 pm. Reply #

defeniately bookmarked

by teddie on December 9, 2009 at 8:49 pm. Reply #

buraya birseyler karalamak gerekiyor ama tam olarak ne yazacagimi bilmiyorum.

by patik modelleri on December 19, 2009 at 3:52 am. Reply #

What licence is use for this tool?

by BoBsoN on December 20, 2009 at 8:50 am. Reply #

Thanks for this code. There’s a lot of typos in it:
$desciption for $description
genarate for generate
Univarsel for Universal

It makes the code hard to read and search.

by Gabe on January 2, 2010 at 6:16 am. Reply #

Thanks for this useful piece of soft.
But please, insert the license in the code, since it’s required by the GPL to apply : http://www.gnu.org/licenses/gpl-howto.html
and it’s much easier to reuse your work.

by Guillaume Allegre on January 7, 2010 at 3:30 pm. Reply #

Very informative content will subscribe to your RSS Feed.

by ED on January 7, 2010 at 11:42 pm. Reply #

[...] PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM) – Let’s explore the web te… (tags: rss feed generator php webdesign) [...]

by links for 2010-01-08 - Ça?da? Polat on January 9, 2010 at 7:36 am. Reply #

Thanks for the valuable resource you have given, i have implementated to my portal. but still tuning it as per my need

thanks :)

by Apsira on January 12, 2010 at 2:10 pm. Reply #

Thanks for article. Keep up sharing.

by diancitie on February 5, 2010 at 7:57 am. Reply #

Works like it says on the tin!

Perfect Thanks!

by Chis on February 6, 2010 at 11:33 pm. Reply #

I’m not sure how other people were able to get this to work straight out of the box. The copy I downloaded from this site has a flaw that means none of the elements closed properly. To fix it change line 301 of FeedWriter.php to:
$nodeText .= (in_array($tagName, $this->CDATAEncoding))? “]]>” : “”;

The original code is missing the slashes:
$nodeText .= (in_array($tagName, $this->CDATAEncoding))? “]]>” : “”;

Hope that might save someone some time.

by Simon on March 7, 2010 at 8:14 am. Reply #

Sorry, that should read:
$nodeText .= (in_array($tagName, $this->CDATAEncoding))? “]]></$tagName>” : “</$tagName>”;

by Simon on March 7, 2010 at 8:17 am. Reply #

[...] PHP Universal Feed Generator [...]

by Useful PHP Classes and Components « UR-Technology on March 7, 2010 at 8:24 am. Reply #

[...] ?????PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM) ??????????????????????PHP4??????FeedWriter?PHP4??????????????? [...]

by RSS??????????? « WineDB info. on March 9, 2010 at 8:54 am. Reply #

Your posts always show me that you really have some indepth knowledge about this. Quite a valuable read i must say

by Conrad Klett on March 13, 2010 at 2:42 am. Reply #

thnaks for sharing

by Ayr?l?k Büyüsü on March 18, 2010 at 5:47 pm. Reply #

How do I add an image inside the description tag?

by Noon on March 19, 2010 at 12:53 pm. Reply #

This is a very beautiful and useful program. This code can easily prepare the RSS link on my pages.

by Betsson Burada on March 20, 2010 at 1:52 am. Reply #

It worked as intended. Took less than 10 minutes of implementantion to get it working, retrieving info from my db and writing the feeds.
Thanks a bunch!

by lalo pantera negra on April 3, 2010 at 11:25 am. Reply #

If anyone is still looking to add the feed validator’s atom:link suggestion: change the genarateFeed function in FeedWriter.php as follows:

/**
* Genarate the actual RSS/ATOM file
*
* @access public
* @return void
*/
public function generateFeed()
{
header(“Content-type: text/xml” . ‘; charset=utf-8′);

$this->printHead();
$this->printChannels();
echo ‘channels['link'] . ‘” rel=”self” type=”application/rss+xml” />’;
$this->printItems();
$this->printTale();
}

I also corrected the function name type and added charset=”utf8″. This is just a quick fix if you only generate RRS2 feeds. Some refactoring is in order for a real fix of course.

by Kris Lamote on April 4, 2010 at 5:04 am. Reply #

Hi, I’m using the RSS 2.0 and it seems tobe working alright, but for some reason it doesnt appear right on IE 7. IE just displays XML rather than in HTML format. Has any of you came across this problem too?

by Riz on April 5, 2010 at 8:47 am. Reply #

???? ?????? ???? ???? ?? ????????!

by yyjkbc on April 6, 2010 at 8:05 am. Reply #

[...] Feedwriter : vient boucler la marche en générant le flux complet [...]

by Un logiciel pour compléter les flux RSS tronqués – Philippe Scoffoni on April 8, 2010 at 3:04 am. Reply #

[...] the facebook and twitter pages automatically by using the sites RSS feed. I found a script from here that uses PHP to create an RSS feed. It works great but I’m having an issue with images [...]

by Capstone Journal 23 « Project Journal on April 10, 2010 at 5:26 am. Reply #

This is a very beautiful and useful program. This code can easily prepare the RSS link on my pages.

by güvenlik kameras? on April 16, 2010 at 3:39 am. Reply #

Thanks for sharing this, saved me lots of time.

by avanzu on April 16, 2010 at 6:11 pm. Reply #

[...] PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM) [...]

by PHP ?? RSS/ATOM pubDate/created ???? » ?? on April 18, 2010 at 2:07 pm. Reply #

[...] some research I found a somewhat easy to use and expand RSS module PHP Universal Feed Generator. It didn’t support the Atom rights tag and of course no GeoRSS tags. But it is quite easily [...]

by GeoRSS and PHP » Publisher.de on April 26, 2010 at 1:54 am. Reply #

Thanks for the script… now just need to get it work on my site… there is no readme file with short description?

by Pera Webbhotell on May 2, 2010 at 3:10 am. Reply #

[...] wie Liferea, Google Reader und Co. abrufen. Man bedient sich dabei PHP, Readability, SimplePie und FeedWriter. Readability spielt hier den essentiellen Part, da es den Inhalt aus den verlinkten Webseiten [...]

by Vollständige RSS-Feeds mit Content-Only | Linux und Ich on May 15, 2010 at 6:47 am. Reply #

RSS Feeds are really very helpful and you could get site and news updates from it.,`;

by Isobel Shaw on May 20, 2010 at 11:13 pm. Reply #

Creating your own RSS feed is a pain in the butt, I am glad others make scripts to complete this task.

by As Seen on TV on June 17, 2010 at 3:11 am. Reply #

1.
You use htmlentities() to encode text that goes into non CDATA fields; this produces illegal (undeclared) XML entities.
You should only encode ‘ ” &

2.
You declare encoding=”UTF-8″ in the XML header, but this is entirely platfor dependant. You should add utf8_encode() to be sure that the encoding corresponds to the content, else accented characters will produce errors.

…and if you could correct all the spelling mistakes… ;)

But this is still a nice library – thanks!

by Martin on June 20, 2010 at 4:09 am. Reply #

Missing atom:link with rel=”self”
how to achieve this?

by Vpills on June 20, 2010 at 7:16 pm. Reply #

I tried for over an hour but couldn’t get this script to work. Bugs in FeedWriter.php and elsewhere. Looks great but doesn’t seem to work :(

Is this script out of date?

by Ted on June 26, 2010 at 3:26 pm. Reply #

HI, great post.

but how can I use ISO-8859-1 ?

by Ocean on June 27, 2010 at 4:34 pm. Reply #

It’s a great solution to get RSS feed implemented in your web site

by Justin on July 10, 2010 at 2:59 am. Reply #

Hi I’m new to this kind of thing so please bear with me. How do I incorporate this into my site? Do I just follow the way you encoded the information in the examples? Please help.

by Adrian on July 11, 2010 at 11:30 am. Reply #

excellent !!!!

by xuedi on July 26, 2010 at 2:39 pm. Reply #

Hi, Thanks for such a wonderful script. Can you tell me how it works?

by Mohanakrishnan on July 27, 2010 at 8:57 pm. Reply #

RSS feeds are really great because you are always updated with the latest news or blog posts.*-*

by Evan Foster on July 28, 2010 at 2:12 pm. Reply #

thanks for this script, had a little problem when trying to use it for the first time, but got around it

by hd vision sunglasses reviews on August 9, 2010 at 12:51 pm. Reply #

I use atom feed but i have problem with the Greek characters, i m trying to load it from my database and it give me back the letters as Special characters(like: &beta) on “View page Source” but that happen only to , on the is everything ok. I have tried to chance the live 298 with this code: htmlentities($tagContent, ENT_QUOTES, ‘UTF-8′); and i don’t know why but somehow it strip the slashes from the tags. Anybody know how can i fix that?

Thanks in advance.

by John on August 11, 2010 at 8:45 am. Reply #

How can add this feed creator in my website

by vijaykumar on August 20, 2010 at 2:48 pm. Reply #

[...] unabridged Blackbeard ale cutting yourself cheap airline tickets the berkley horse Cervical cancer abbreviations capital voice box nodule a list of spring flowers Reply With [...]

by barbara digiacomo on August 23, 2010 at 11:57 am. Reply #

Will this class also take care of cleaning the data. Like if you have for instance data that holds html or even worse xml in it will it make sure it won’t break the rss feed produced?

by Edwin on September 3, 2010 at 8:06 am. Reply #

RSS feeds are really great if you want to stay updated ;*,

by Kylie Sanchez on September 14, 2010 at 8:17 pm. Reply #

Tested the script and it works wonderfull

by Madopskrifter on September 20, 2010 at 9:28 pm. Reply #

I use you class to make my rss.
When I tried to validate with feedvalidator says:

“item should contain a guid element”

How I can solve this issue?

Another question:
I’m using utf-8 at my server and my language is spanish. When I put any character with accent the feed don’t work.

Have you any solution?

Thanks in advance.

by nassio on September 21, 2010 at 2:18 pm. Reply #

[...] Clase para generar feeds con php Publicado en PHP por elrincondeseth en Septiembre 22, 2010 PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM) [...]

by Clase para generar feeds con php « El rincon de seth on September 23, 2010 at 12:40 am. Reply #

Using this on Mythtv and if the any of the titles has & characters in it the resulting page will be completely blank.

by Dag Nygren on September 23, 2010 at 3:33 am. Reply #

Thanks for the script. I am really impressed and have been looking for something like this!

by Jerry wheel repair san jose on October 7, 2010 at 10:30 am. Reply #

i use RSS Feeds to syndicate my blog on other blogs*`-

by Driving Lights  on October 13, 2010 at 11:08 pm. Reply #

Outstanding! Quick setup and simple to use. Just the way it should be.

by Al Smith on October 18, 2010 at 7:30 am. Reply #

RSS feeds are necessary for transmitting your blog updates to your readers or followers:~*

by Activated Carbon Filter : on October 25, 2010 at 11:22 am. Reply #

Thanks a lot Sir for this excellent script that will save me time ;)

by Test ADSL on October 26, 2010 at 3:28 am. Reply #

I use this script on all my sites – Outstanding!

by Rich Linecum on November 9, 2010 at 5:17 am. Reply #

Hi There,

Thank you for the class, works really great (after a couple of minutes of tweaking and setting up)…

Just one thing I would like to confirm. Your closing tags for the items, none of the close with or etc… Is this suppose to be like this? I was unable to get the feed to work until I modified the FeedWriter.php file on line 304 : $nodeText .= (in_array($tagName, $this->CDATAEncoding))? “]]>” : “”;

It works perfectly now.

by Lord-Nikon on November 16, 2010 at 7:19 pm. Reply #

Ok, your blog strips out code so my previous comment will make absolutely no sense at all. Basically would like to know why your closing tags on line 304 of the FeedWriter class do not start with a backslast ? I only got it to work after changing your class :( But thanks again for an excellent class!

by Lord-Nikon on November 16, 2010 at 7:21 pm. Reply #

Really like this, saved me at least three days of work! :) Thanks m8!

by Bart From Holland on November 21, 2010 at 3:50 am. Reply #

Simple to integrate to my current PHP code and works very well!

by ginger bread man on December 14, 2010 at 2:10 pm. Reply #

thanks for the work on the libary. may i note that it’s “generate” not “genarate”?

by Leho Kraav on December 20, 2010 at 12:17 am. Reply #

i think that RSS FEEDS should also be included on the list of the best inventions because it makes life easier for bloggers like us ,”"

by Fishing Umbrella on December 23, 2010 at 12:17 am. Reply #

[...] PHP Universal Feed Generator PHP Universal Feed Generator is a class that allows you generates both ATOM and RSS feeds from your database records. It support all possible feed elements and you can easily define channel and feed items. [...]

by 50+ Extremely Useful PHP Classes & Libraries « The World of PHP on January 8, 2011 at 1:01 pm. Reply #

Recently I did a search on the issue and found a great number of persons will agree with your blog!

by ???? on January 8, 2011 at 2:24 pm. Reply #

Great!

by Lawrence on January 17, 2011 at 9:53 am. Reply #

I have appreciated your current article keep up the great work. This particular subject matter provides always fascinated myself.

by mattress disposal on January 18, 2011 at 3:02 am. Reply #

for displaying non-english characters in item title, don’t forget to change line 42 to:

$this->CDATAEncoding = array(‘title’, ‘description’, ‘content:encoded’, ‘summary’);

by Rakshaasa on January 18, 2011 at 3:22 am. Reply #

How do I change the link address so that it has the format ‘article.php?ID=xx’ where xx is the NewsID from database table?

Which file do I edit?

by Heckie on January 18, 2011 at 5:21 pm. Reply #

Your a lifesaver!

This will make it easier for me to update my feeds :)
Combining your script with Feedburner updates my Facebook & Twitter profile on the fly.

by Oguzhan on January 19, 2011 at 8:35 am. Reply #

Outstanding information! I’m glad to know there still are some real blogs these days which are truely worth reading.

by Cheap Skinny Jeans For Men on January 19, 2011 at 4:03 pm. Reply #

-.’ I am very thankful to this topic because it really gives great information *”.

by Diabetic Neuropathy on January 25, 2011 at 7:20 pm. Reply #

Thank you so much for making this AND documenting it well.
I used it for a unique situation where I had to pull XML from weather.gov into a PHP XML parser, create an RSS, and post it to an .aspx website.

by Tyler on January 27, 2011 at 11:24 pm. Reply #

Awesome Script…

by Rajendr on September 6, 2011 at 7:13 pm. Reply #

Thanks for the blog strips.there is something very unique and enjoyable about.

by Joseph Taylor Culturextourism Expert on September 7, 2011 at 1:45 pm. Reply #

Thank ! Great change and I am glad that you posted a workaround for us using Mantis partially inside a frame . However having configurations options for this would a be a real highlight.

by Great Application on September 12, 2011 at 5:17 pm. Reply #

Looks good; thanks for sharing it Have you thought about publishing your code on github (or someplace similar)? It is quite nice for collaboration, and allows you to easily evaluate and merge suggested fixes / improvements.

by Brian on September 13, 2011 at 6:49 pm. Reply #

Thanks buddy, you saved me three hours and now I have a decent generator rather than whatever basic thing I’d have come up with ;-)

by Mike on September 21, 2011 at 1:08 am. Reply #

And what about sitemap ? Does it support to create sitemaps ? :) If yes, would be excellent.. Thanks anyways

by filmi indir on September 25, 2011 at 6:36 pm. Reply #

Thanks so much for this. I need a rss feed for my website badly.

by 4chan on September 20, 2012 at 6:17 pm. Reply #

@Brian: Just found out this code is already on github:

https://github.com/ajaxray/FeedWriter
(I’ve forked and changed the link — ajaxray)

by Mike on December 16, 2012 at 10:57 pm. Reply #

Sorry the download link is down. Added github link.

by admin on December 17, 2012 at 2:02 pm. Reply #

Leave your comment

Required.

Required. Not published.

If you have one.