RSS_PHP v1 Documentation
RSS_PHP is a PHP 5 class which allows the easy conversion of RSS to a workable PHP Object.
RSS_PHP Object Properties
The RSS_PHP Object contains 3 properties; all readable and writable.
- RSS_PHP->document; - Contains the entire RSS Document converted to an Array.
- RSS_PHP->channel; - Contains the an Array of all nodes which are not classed as an Item, or a child of Item.
- RSS_PHP->items; - Contains an Array of all the <item>'s found in the RSS Document
All properties can be accessed direcly via RSS_PHP->items; or via it's respective method i.e. RSS_PHP->getItems(); [recommended]
The Basic RSS_PHP Object Structure
rss_php Object
(
[document] => Array
(
[rss] => Array
(
[properties] => Array
(
[version] => 2.0
)
[value] => Array
(
[channel] => Array
(
[value] => Array
(
[title] => Array
(
[value] => RSS_PHP : RSS Parser for PHP 5+
)
[link] => Array
(
[value] => http://rssphp.net/
)
[description] => Array
(
[value] => RSS_PHP is a single class which utilises the DOM to parse any RSS feed into a simple Object comprising of three Array's.
)
[pubDate] => Array
(
[value] => Tue, 15 Jan 2008 02:01:46 -0500
)
[generator] => Array
(
[value] => http://rssphp.net/
)
[language] => Array
(
[value] => en
)
[item:0] => Array
(
[value] => Array
(
[title] => Array
(
[value] => RSS_PHP News Item
)
[link] => Array
(
[value] => http://rssphp.net/latest-news/
)
[pubDate] => Array
(
[value] => Tue, 15 Jan 2008 02:01:45 -0500
)
[dc:creator] => Array
(
[value] => rssphp
)
[category] => Array
(
[value] => Site Launches
)
[description] => Array
(
[value] => Today a new site launched a PHP based RSS Parser [...]
)
[guid] => Array
(
[properties] => Array
(
[isPermaLink] => false
)
[value] => http://rssphp.net/latest-news/
)
)
)
)
)
)
)
)
[channel] => Array
(
[title] => Array
(
[value] => RSS_PHP : RSS Parser for PHP 5+
)
[link] => Array
(
[value] => http://rssphp.net/
)
[description] => Array
(
[value] => RSS_PHP is a single class which utilises the DOM to parse any RSS feed into a simple Object comprising of three Array's.
)
[pubDate] => Array
(
[value] => Tue, 15 Jan 2008 02:01:46 -0500
)
[generator] => Array
(
[value] => http://rssphp.net/
)
[language] => Array
(
[value] => en
)
)
[items] => Array
(
[0] => Array
(
[value] => Array
(
[title] => Array
(
[value] => RSS_PHP News Item
)
[link] => Array
(
[value] => http://rssphp.net/latest-news/
)
[pubDate] => Array
(
[value] => Tue, 15 Jan 2008 02:01:45 -0500
)
[dc:creator] => Array
(
[value] => rssphp
)
[category] => Array
(
[value] => Site Launches
)
[description] => Array
(
[value] => Today a new site launched a PHP based RSS Parser [...]
)
[guid] => Array
(
[properties] => Array
(
[isPermaLink] => false
)
[value] => http://rssphp.net/latest-news/
)
)
)
)
)
RSS_PHP->load()
RSS_PHP->load(string $url, bool $unblock) - Load an RSS Document from a valid URL into the RSS_PHP Object
if $unblock is TRUE [default] then RSS_PHP will attempt to immitate a user-agent to prevent the HTTP Request from being blocked.
<?php
$RSS_PHP = new rss_php;
$RSS_PHP->load('http://news.google.com/?output=rss');
?>
RSS_PHP->loadRSS()
RSS_PHP->loadRSS(string $rss) - Load an RSS Document from a string into the RSS_PHP Object
<?php
$LATIN1_Document = file_get_contents('http://rssphp.dev/verify/rss_1.0/rss.xml');
$UTF8_Document = utf8_encode($LATIN1_Document);
$RSS_PHP = new rss_php;
$RSS_PHP->loadRSS($UTF8_Document);
?>
RSS_PHP->getRSS()
RSS_PHP->getRSS(bool $includeAttribues) - Return the complete RSS Document as an Array, if $includeAttribues is TRUE then attributes are included.
<?php
$RSS_PHP = new rss_php;
$RSS_PHP->load($url);
$rss_basic = $RSS_PHP->getRSS(); #return the document property WITHOUT attributes
$rss_full = $RSS_PHP->getRSS(true); #return the document property WITH attributes
?>
RSS_PHP->getChannel()
RSS_PHP->getChannel(bool $includeAttribues) - Return the RSS Documents Channel data as an Array, if $includeAttribues is TRUE then attributes are included.
<?php
$RSS_PHP = new rss_php;
$RSS_PHP->load($url);
$channel_basic = $RSS_PHP->getChannel(); # return the channel property WITHOUT attributes
$channel_full = $RSS_PHP->getChannel(true); # return the channel property WITH attributes
?>
RSS_PHP->getItems()
RSS_PHP->getItems(bool $includeAttribues) - Return the RSS Document Items as an Array, if $includeAttribues is TRUE then attributes are included.
<?php
$RSS_PHP = new rss_php;
$RSS_PHP->load($url);
$items_basic = $RSS_PHP->getItems(); # return the item property WITHOUT attributes
$items_full = $RSS_PHP->getItems(true); # return the item property WITH attributes
?>
includeAttributes
If includeAttribues is ommited or set to false [default], then attributes are not included in the return array; below is a short sample of data produced by RSS_PHP->getItems();.
Array
(
[0] => Array
(
[title] => RSS_PHP Test News Item
[link] => http://rssphp.net/test-news/
[pubDate] => Tue, 15 Jan 2008 03:08:15 -0500
[dc:creator] => rssphp
[category] => Test News
[description] => A short test article to demonstrate RSS_PHP [...]
[guid] => http://rssphp.net/test-news/
)
[1] => . . .
RSS_PHP Note:
RSS_PHP reset's itself on every load() and loadRSS(); meaning it is completely re-usable.
RSS_PHP Internationalization and Character Encoding Support
v3 of RSS_PHP features full encoding support and translation, however RSS_PHP v1 uses the UTF-8 Character Encoding by default, this is a dependency of PHP's DOM; to quote from source:
Use utf8_encode() and utf8_decode() to work with texts in ISO-8859-1 encoding or Iconv for other encodings.