PHP RSS Parser
PHP 5 allows one to create a RSS parser in a few simple steps. Unfortunately, most hosting companies are still on PHP 4 or in some cases even lower than that. I came across a great simple and powerful RSS parser called lastRSS.
Features
All RSS versions supported (0.9, 1.0 and 2.0) Transparent cache (doesn’t cache RSS file directly, neither HTML output, but serialized variable; cached data isn’t parsed every time, but you can still access individual fields) pubDate/lastBuildDate conversion to any date/time format Character encoding conversion (all encodings supported by iconv library) Returns an associative array with RSS fields Regullar expression parsing (very quick) Strips HTML from description (both hard-coded and entity-coded) Optional limit the number of returned items Two ways how to proceed CDATA information (get/strip CDATA content) Free open-source software (GNU/GPL)
Sample
[php]
// include lastRSS
include "./lastRSS.php";
// Create lastRSS object
$rss = new lastRSS;
// Set cache dir and cache time limit (1200 seconds)
// (don't forget to chmod cahce dir to 777 to allow writing)
$rss->cache_dir = ”;
$rss->cache_time = 0;
$rss->cp = ‘US-ASCII’;
$rss->date_format = ‘l’;
// Try to load and parse RSS file of Slashdot.org
$rssurl = ‘http://www.freshfolder.com/rss.php’;
if ($rs = $rss->get($rssurl)) {
echo ‘
';
print_r($rs);
echo '
‘;
}
else {
echo “Error: It’s not possible to get $rssurl…”;
}
?> [/php]































