A Simple RSS Feed Phraser in PHP
Heres a simple RSS Feed Phraser function. Its simple and effective function. All you need to do is add it to the page you wish to display the feed.
If you want to show / display the feed all you need to do is call up the function using:
The $variables can be used to define a few options:
$url = the url of the rss feed (e.g. http://slashdot.org/slashdot.rdf)
$count = the number of titles and descriptions to display (e.g. 5)
Using this function you can display more than one rss feed in one page / file, without constantly rewriting out all the code to display the feed. The function:
Enjoy!
Heres a simple RSS Feed Phraser function. Its simple and effective function. All you need to do is add it to the page you wish to display the feed.
If you want to show / display the feed all you need to do is call up the function using:
PHP Code:
showFeed($url,$count);
The $variables can be used to define a few options:
$url = the url of the rss feed (e.g. http://slashdot.org/slashdot.rdf)
$count = the number of titles and descriptions to display (e.g. 5)
Using this function you can display more than one rss feed in one page / file, without constantly rewriting out all the code to display the feed. The function:
PHP Code:
function showFeed($url,$count)
{
//* get the xml file
$xml = simplexml_load_file($url);
//* phrase all the data from the xml so we can display it
for ($x = 0; $x < $count; $x++) {
//* this bits for if its an rss 1 feed
if (isset($xml->item)) {
$item = $xml->item[$x];
}
//* this bits for 0.91 rss feeds
elseif (isset($xml->channel->item)) {
$item = $xml->channel->item[$x];
}
//* show the headline and the description
echo "<a href=\"$item->link\">$item->title</a><br>$item->description<br><br>";
}
//* reset variables
unset($xml);
unset($item);
//* close the function loop
}
Enjoy!
Comment