RSS Class
The code snippet is a PHP class for retrieving RSS feeds from the DaniWeb website. There are two exposed methods, one for retrieving the list of predefined article types, and another to get a specific RSS feed. If you pass parameters to this method, there is a basic check to see if the forum ID is an integer and greater than zero. The article type will be checked against the predefined list.
To do
I want to combine this class later with the DaniWeb API, so it can retrieve a valid list of forum ID's to choose from. For now, I'll leave that as an exercise for you to add.
Another addition can be to add the XML parsing into the class, so it can return the result in an associative array.
Usage example
include 'Rss.class.php';
$rss = new Rss();
// Get the list of predefined article types.
$articleTypes = $rss->GetArticleTypes();
// Get the RSS feed for unanswered Hardware and Software quetions.
$feed = $rss->GetFeed(1, 'unanswered');
if ($feed)
{
// Taken from the API documentation.
$articles = new SimpleXMLElement($feed);
foreach ($articles->channel->item as $article)
{
echo '<a href="' . $article->link . '">' . $article->title . '</a><br />';
}
}