VB icon

RSS/XML News Feed Parser

Email
Submitted on: 1/1/2015 12:08:00 PM
By: CT Sirius (from psc cd)  
Level: Advanced
User Rating: By 11 Users
Compatibility: PHP 4.0
Views: 654
 
     This code parses an XML/RSS news feed document that resembles something like this feed: http://www.webfroot.co.nz/b2/b2rss.php. It makes each title a link to the actual article. Please see the image and/or http://members.lycos.co.uk/ctsirius/parse.php !

 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
// for :RSS/XML News Feed Parser
//**************************************
You are free to use it and redistribute unmodified.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: RSS/XML News Feed Parser
// Description:This code parses an XML/RSS news feed document that resembles something like this feed: http://www.webfroot.co.nz/b2/b2rss.php. It makes each title a link to the actual article. Please see the image and/or http://members.lycos.co.uk/ctsirius/parse.php !
// By: CT Sirius (from psc cd)
//
// Inputs:The only variable that usually needs to be modified is the source of the news feed. The number of bytes to read may need to be modified in the case of a VERY large news feed, which it does not completely read.
//
// Returns:The code returns the links, within a paragraph html tag.
//
// Assumes:I am assuming the user is including the file, and therefore it does not echo out the XHTML header data (i.e. <html>,<head>, or <body>).
//
// Side Effects:None.
//**************************************

<?
//The file to Parse, (i.e) Web Address.
$file = "http://www.webfroot.co.nz/b2/b2rss.php";
//Number of Bytes to Read. 10000 Should be Enough.
//Increase only if it does not read the entire file.
$byte = "100000";
//No more editing.
$ofile = @fopen("$file", "r");
$contents = @fread ($ofile, $byte);
@fclose($ofile);
if(!$contents)
{
echo "<p>\nUnable to Get XML/RSS data. Fatal Error.\n</p>";
exit;
}
preg_match_all ("'<title>(.*?)</title>'si", $contents, $titles);
preg_match_all ("'<link>(.*?)</link>'si", $contents, $link);
$count = count($titles[1]);
$link = $link[1];
$titles = $titles[1];
echo "<p>\n";
for($i = 0; $i <= $count; $i++)
{
echo "<a href=\"$link[$i]\">$titles[$i]</a>\n<br />\n";
}
echo "</p>";
?>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.