About

RssUtil is a PHP library, which helps generate RSS contents. Any data on web page can be used in RSS. With RssUtil you simply create new instances of Rss, Channel and Item objects and build a complete RSS tree structure. Fill the objects with data and wrap them into XML with RSS contents to feed your web page users.
Developers might find it quite useful since it simplifies generation of RSS feeds. Create instances of Rss, Channel and Item objects and populate the variables. At the end simply call generateXml() method to retrieve xml with rss data and pass it to the user.
RssUtil is open source project. It is written in PHP. Use it freely and wisely.


Install

RssUtil is PHP file (rssutil.php). Put it next to your PHP code, or any other location you like.


How to implement

When you are building a RSS elements keep in mind the tree structure of RSS in XML document:

Rss
 + - Channel
 |     + - Item
 |     + - Item
 |     + - ...
 + - Channel
 |     + - Item
 |     + - ...
 + - ...


1. Create new Rss object
2. Create new Channel object
3. Create new Item objects and add each Item to the Channel
4. Add Channel object to Rss object
(5). Optionally create more Channels and Items
6. Generate XML (string)

example.php

<?php

include_once 'rssutil.php';

$rss = new Rss();

$channel = new Channel();
$channel->title = "Hello RSS";
$channel->link = "http://www.matjazcerkvenik.si";
$channel->description = "Test RSS feeds";
$channel->language = "en-us";
$channel->pubDate = date("D, d M Y H:i:s T");
$channel->docs = "http://www.matjazcerkvenik.si";
$channel->managingEditor = "matjaz@matjazcerkvenik.si";

$item1 = new Item();
$item1->title = "Developer's corner";
$item1->link = "http://www.matjazcerkvenik.si/developer";
$item1->description = "Learn web technologies: HTML, CSS, PHP, JavaScript...";
$item1->pubDate = "Sat, 12 Aug 2011 13:45:51 CEST";

$channel->addItem($item1);

$item2 = new Item();
$item2->title = "Photo Gallery";
$item2->link = "http://www.matjazcerkvenik.si/photogallery";
$item2->description = "New photos from around the world";
$item2->pubDate = "Sat, 03 Sep 2011 22:52:16 CEST";

$channel->addItem($item2);

// add more items

$rss->addChannel($channel);

// add more channels (and items)

header("Content-Type: application/rss+xml");
echo $rss->generateXml();

?>



Before running your code, put the following line in the <head> element of your web page:


<link rel="alternate" type="application/rss+xml" href="http://LINK/TO/YOUR/RSS/example.php" title="Hello RSS" />

Some browsers can detect RSS feeds and automatically display them as styled html document. Anyway, if you don't see generated xml, choose 'view source code'. The output should look like this:



<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>Hello RSS</title>
<link>http://www.matjazcerkvenik.si</link>
<description>Test RSS feeds</description>
<language>en-us</language>
<pubDate>Sat, 03 Sep 2011 23:50:13 CEST</pubDate>
<docs>http://www.matjazcerkvenik.si</docs>
<managingEditor>matjaz@matjazcerkvenik.si</managingEditor>
<item>
<title>Developer's corner</title>
<link>http://www.matjazcerkvenik.si/developer</link>
<description>Learn web technologies: HTML, CSS, PHP, JavaScript...</description>
<pubDate>Sat, 12 Aug 2011 13:45:51 CEST</pubDate>
</item>
<item>
<title>Photo Gallery</title>
<link>http://www.matjazcerkvenik.si/photogallery</link>
<description>New photos from around the world</description>
<pubDate>Sat, 03 Sep 2011 22:52:16 CEST</pubDate>
</item>
</channel>
</rss>


Remark: Date should be formated as: D, d M Y H:i:s T , where
D - name of the day, three letters (Mon, Tue...)
d - day of month, 2 digits with leading zeros
M - textual representation of the month, three letters (Jan, Feb...)
Y - year, 4 digits
H - 24-hour format, 2 digits with leading zeros
i - minutes, 2 digits with leading zeros
s - seconds, 2 digits with leading zeros
T - timezone (GMT, CEST...)


Download

Current version: 1.0

RssUtil-v1.0.zip

If you believe you found a bug, please report to: matjaz@matjazcerkvenik.si


Disclaimer

I do not take any responsibility regarding the usage (or misusage) of RssUtil library.

september 2011