VB icon

MEL :: RSS And XML Parse Function

Email
Submitted on: 1/1/2015 10:00:00 PM
By: Melvin D. Nava (from psc cd)  
Level: Intermediate
User Rating: By 8 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 1917
 
     **UPDATED** This function will parse your favorite XML and RSS news feeds in a nice format. Only one variable to set up and easy to integrate and modify. Tested on several sources. Let me know this has been useful. Comments and suggestions are very much appreciate it. **Please Vote**

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: MEL :: RSS And XML Parse Function
// Description:**UPDATED** This function will parse your favorite XML and RSS news feeds in a nice format. Only one variable to set up and easy to integrate and modify. Tested on several sources. Let me know this has been useful. Comments and suggestions are very much appreciate it. **Please Vote**
// By: Melvin D. Nava (from psc cd)
//**************************************

<?php
//
// The Function
// By Melvin D. Nava
// http://mdnava.network.com.ve/
//
function parse_rss($f) {
	$xmlfile = fopen($f, 'r');
	if (!$xmlfile) die('cannot open the xml file');
	$readfile = fread($xmlfile ,40000);
	$parsefile = eregi("<item>(.*)</item>", $readfile ,$arrayreg);
	$filechunks = explode("<item>", $arrayreg[0]);
	$count = count($filechunks);
	echo '<font face=verdana><ul>';
	for($i=1 ; $i<=$count-1 ;$i++) {
		ereg("<title>(.*)</title>",$filechunks[$i], $title);
		ereg("<link>(.*)</link>",$filechunks[$i], $links);
		ereg("<description>(.*)</description>",$filechunks[$i], $description);
		echo str_replace('hxaxh','a',"<li><font style='font-size: 12px;'><hxaxh target=_blank href ='$links[1]'\>".utf8_decode($title[1])."</hxaxh></font>");
		echo "<br><font color=gray style='font-size: 10px;'>".utf8_decode($description[1])."</font></li>";
	}
	// feel free to remove next notice
	// is not needed by this function
	echo '</ul><font style="font-size: 10px;">Better News Grabber by ';
	echo str_replace('hxaxh','a','<hxaxh target=_blank href="http://mdnava.network.com.ve/">Melvin D. Nava</hxaxh></font></font></font>');
}
//
// The Example
//
echo '<h1>Star Wars News</h1>';
$xmlfeed = 'http://www.starwars.com/community/webmasters/starwars.rdf';
parse_rss($xmlfeed);
?>


Other 1 submission(s) by this author

 


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 Intermediate 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.