Friday, May 1, 2009

XML-based RSS parser in PHP

MagpieRSS provides an XML-based RSS parser in PHP.

Link:
http://magpierss.sourceforge.net/

Download:
http://sourceforge.net/project/showfiles.php?group_id=55691


How to Use:
- Download magpierss-version.tar.gz file
- Extract downloaded file.
- include magpierss-version/rss_fetch.inc file in your php file.

require('rss_fetch.inc');
$rss = fetch_rss($url);

- ready to parse RSS



A Simple Example:

require_once 'rss_fetch.inc';

$url = 'http://www.example.com/rss/today.xml';
$rss = fetch_rss($url);

echo "Site: ", $rss->channel['title'];

foreach ($rss->items as $item ) {
$title = $item[title];
$url = $item[link];
echo $title . "," . $url ;
}

No comments: