Php Feed Generator - Free Php Class (Custom feed in 5 Simple Steps) - WebmasterHub.net Blog

Php Feed Generator - Free Php Class (Custom feed in 5 Simple Steps)


How to generate custom Atom and RSS feeds with Php

Php FeedWriter is a free Php package that allows RSS and Atom feeds to be generated using a single script.  Build and populate your feed from your database or static content once, then allow users of your website to subscribe to view the feed in many common formats, including Atom 1.0 and RSS 2.0.  Other output formats are also supported as well making your custom feeds highly compatible with feed readers and aggregators.

Below is a simple step by step tutorial to create a basic feed using the free class that build upon the sample scripts available to download from the official website.  Class documentation is provided to help use the class when constructing your feed from database or static content.


Tutorial Steps: Generate Feed using Php:

1. Download the free Php Feed Generator Class, and extract the contents of the package to your web server.
In this tutorial, I have extracted the contents of the package into a "includes" directory accessible from the root of the web server.  The package contains a FeedWriter.php file and FeedWriter directory that contains the other class files.
2. Create a new Php file named "feed.php" that will be used to serve the feed content.
3. Copy the following code into the feed.php file to get started.
<?php
require_once("includes/FeedWriter.php");
$feed = new FeedWriter('Feed Title', 'Description', 'http://webmasterhub-blog.blogspot.com/');
This instantiates a new FeedWriter object with the title, description and link.  The link should point to the hompage of your website.
4. Add an item to the feed:
$feed->add_item('Item Title' , 'Item Content', 'Item Link');
This will add an item to the feed. The link should point to the page containing the content included in the item.
5. Display the feed
echo $feed->getXML('RSS_0_92');
This will display a RSS 9.92 compatible feed. Other formats supported include:
  • Atom_1 (Atom 1.0)
  • RSS_2_0 (RSS 2.0)
  • RSS_1_0 (RSS 1.0)
  • RSS_0_91 (RSS 0.91)
Depending on the format used, you may need to include additional information in the feed or items in the feed for it to be valid.  This can be done easily using the functions provided by the FeedWriter class.  The class documentation can assist with adding other (optional) information to the feed if required, which is available from the Php FeedWriter website.

The Php FeedWriter website also provides a range of sample scripts that allow the format to be determined from a query string parameter.

A more comprehensive tutorial on how to build custom feeds using Php FeedWriter can be found here: How to Generate Feed Using Php (Atom 1.0 and RSS 2.0 Compatible)

0 comments

Post a Comment

 
|  WebmasterHub.net Blog. Blogger Template By Lawnydesignz Powered by Blogger