PHP Classes

File: feed.class.php

Recommend this page to a friend!
  Classes of Md. Kausar Alam   RSS feed class   feed.class.php   Download  
File: feed.class.php
Role: Example script
Content type: text/plain
Description: Possible to create feed
Class: RSS feed class
Regenerate an RSS 2.0 feed from another RSS feed
Author: By
Last change:
Date: 15 years ago
Size: 3,631 bytes


Class file image Download
 * An open source application development framework for PHP5
 * @author Md. Kausar Alam (kausar_ss2003(at)
 * @since Version 1.0
 * file namw feed.class.php
 * @filesource

// xmlGenerator class
class feedGenerator

//call constractor
function feedGenerator($xml)
$this->xmlDoc = new DOMDocument();
    * get link/description/title
    * eleminate the unwnate char repalceing HTML char
function replaceHTMLCharacter($str)
$str = preg_replace('/&/', '&amp;', $str);
$str = preg_replace('/</', '&lt;', $str);
$str = preg_replace('/>/', '&gt;', $str);
$str = preg_replace('/\"/', '&quot;', $str);
$str = preg_replace('/\'/', '&apos;', $str);

// get header only
function getHeader()
$channel = $this->xmlDoc->getElementsByTagName('channel')->item(0);
// get channel title
$channel_title = $channel->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
$item_title = $this->replaceHTMLCharacter($item_title);
// get channel link
$channel_link = $channel->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
$channel_link = $this->replaceHTMLCharacter($channel_link);
// get channel description
$channel_desc = $channel->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;
$channel_desc = $this->replaceHTMLCharacter($channel_desc);
//return header
return '<?xml version="1.0" encoding="UTF-8" ?>
                 <rss xmlns:dc="" version="2.0">
// main body of xml file here generate
function getBody()
$strBody= "";
//get and output "<item>" elements
$x= $this->xmlDoc->getElementsByTagName('item');
//loop will continue untill out site's xml file has finished
for ($i=0; $i<$x->length; $i++)
//get title
$item_title = $x->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
$item_title = $this->replaceHTMLCharacter($item_title);
//get link
$item_link = $x->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
$item_link = $this->replaceHTMLCharacter($item_link);
//get description
$item_desc = $x->item($i)->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;
$item_desc = $this->replaceHTMLCharacter($item_desc);
$strBody= $strBody . '<item><title>'.$item_title.'</title>
                                      <guid isPermaLink="true">'
//return main body of xml file
return $strBody;
//return footer
function getFooter()
//write all data in xml file
function generateXMLFile()
$handle = fopen("feed.xml", "w");
fwrite($handle , $this->getHeader());
fwrite($handle , $this->getBody());
fwrite($handle , $this->getFooter());

// end of class
    //create object
$feedApp =new feedGenerator("");
//write on xml file