logo PHP XML Classes
A collection of classes and resources to process XML using PHP

Description: This class can parse any RSS 1.0 file returning information about the channel, channel_image, channel_textinput and items as PHP arrays. RSS feeds can be parsed from files or URLS. The rssdump.php example can be adapted to display any RSS feed in just 5 secs.

RSS Parser (class_rss_parser.php)
PHP XML Classes
RSS Parser (class_rss_parser.php)

Description: This class implements a full RSS 1.0 parser, RSS documents can be parsed from local files or URLs, then you can retrieve information about the channel, channel_image, channel_textinput and items in the RSS feed. The rssdump.php example can be modified in 5 secs to display an RSS feed in they way you want.

NEWS:
  • 07-04-2002 Documentation updated and package rebuilt.
  • 06-13-2002 First version of this class released.
This class code as well as documentation are hosted at SourceForge please visit our SourceForge page for releases, documentation, bug-tracking, support forums and mailing lists.

Resources Requirements
  • PHP 4.0.5+

Features To-dos
  • All the RSS elements can be obtained.
  • Based on a full RDF parser this class can understand any valid RDF syntax for RSS.
  • If you have some to-do in mind let me know it.

Contact: Luis Argerich (lrargerich@yahoo.com)

Detailed description and usage:

See this example:

$rss=new RSS_parser();
$rss->rss_parse("http://www.phpclasses.org/browse.html/latest/latest.xml");
$ch=$rss->get_channel_data();
$ch_im=$rss->get_channel_image_data();
$ch_ti=$rss->get_channel_textinput_data();
$items=$rss->get_items_data();


The rssdump example shows how to use the information returned by the methods, the structures returned by the get methods are:
  • $ch: channel data: an asoc array with channel information (if present)
  • $ch_im: channel image data: an asoc array with channel image information (if present)
  • $ch_ti: channel textinput data: an asoc array with channel textinput information (if present)
  • $items: An array of asociative arrays containing items information (if present)

Documentation

Classes

RSS_parser

Extends: None
Description: A class based on an RDF parser to parse RSS feeds, it can parse any valid RSS feed and return all the informationcontained in the RSS document.

Method Summary
 Boolean rss_parse(string $rss)
          Parses an RSS document
 Asoc Array get_channel_data(string $rss)
          Returns information about the channel
 Asoc Array get_channel_image_data(string $rss)
          Returns information about the channel image if present
 Asoc Array get_channel_textinput_data(string $rss)
          Returns information about channel's textinput if present
 Array get_items_data(string $rss)
          Returns information about channel's items
 

Method Detail

rss_parse

Boolean rss_parse(string $rss)
This parses an RSS document from a URL or a file storing the information in the object's data members. Accesory functions are provided to retrieve the parsed data.
 
Parameters:
$rss - URL or file name for the RSS document to be parsed
Returns:
True if the feed was parsed succesfully, false if there was an error.
Throws:
None

get_channel_data

Asoc Array get_channel_data(string $rss)
This returns information about the channel described in the RSS feed, it returns an asociative array with the information present in the feed about the channel. For example link, description, image, textinput.
 
Parameters:
Returns:
An asociative array where each key describe a channelproperty if present in the RSS feed.
Throws:
None

get_channel_image_data

Asoc Array get_channel_image_data(string $rss)
This returns an asociative array containing information about the channel image. For example link, title and url
 
Parameters:
Returns:
An asociative array where each key describes a channel image property.
Throws:
None

get_channel_textinput_data

Asoc Array get_channel_textinput_data(string $rss)
Tihs method returns information about the channel's textinput element if present in the RSS feed. It returns an asociative array where each key describes a property of the textinput element, for example: description, link, name, title.
 
Parameters:
Returns:
An asociative array where each key describes a channel's texinput property if present.
Throws:
None

get_items_data

Array get_items_data(string $rss)
This method returns an array of items. Each member of the array is an asociative array describing an item. For each item properties present in the RSS feed are detailed, for example: title, link, description
 
Parameters:
Returns:
An array of asociative arrays. Typical way to parse it: foreach($items as $item) { print("An item:
"); foreach($item as $key=>$val) { print("$key: $val
"); } }
Throws:
None


Contribute!: If you want to contribute a class to this project or help with new versions of existing classes please let me know it by emaill Hosted at:
SourceForge.net Logo
Contact & credits
Luis Argerich
Rogerio

OSI Certified Open Source Software
OSI
RSS FEED XHTML