hitech Posted October 5, 2007 Share Posted October 5, 2007 I am using the following PHP code to parse and show the RSS Feeds: <?php // ***** BEGIN ***** get the q parameter from URL ***** BEGIN ***** $q=$_GET["q"];//find out which feed was selected if($q=="Google") { $xml=("http://rss.terra.com.br/0,,EI1,00.xml"); } elseif($q=="MSNBC") { $xml=("http://feeds.folha.uol.com.br/folha/emcimadahora/rss091.xml"); } $xmlDoc = new DOMDocument(); $xmlDoc->load($xml); // ***** BEGIN ***** get elements from "<channel>" ***** BEGIN ***** $channel=$xmlDoc->getElementsByTagName('channel')->item(0); $channel_title = $channel->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue; $channel_link = $channel->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue; $channel_desc = $channel->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue; //***** BEGIN ***** output elements from "<channel>" ***** BEGIN ***** echo("<p><a href='" . $channel_link . "'>" . $channel_title . "</a>"); echo("<br />"); echo($channel_desc . "</p>"); // ***** BEGIN ***** get and output "<item>" elements ***** BEGIN ***** $x=$xmlDoc->getElementsByTagName('item'); for ($i=0; $i<=10); $i++) { $item_title=$x->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue; $item_link=$x->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue; $item_desc=$x->item($i)->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue; echo ("<p><a href='" . $item_link . "'>" . $item_title . "</a>"); echo ("<br />"); echo ($item_desc . "</p>"); echo("<hr>"); } ?> In this code, the loop for ($i=0; $i<=10); $i++) count 10 items of the feed. How can I parse all items of the feed? I tryed: for ($i=0; $i<=count($x.length); $i++) but doesn´t work. Thanks, Helcio From Brasil Link to comment https://forums.phpfreaks.com/topic/71925-rss-reader-with-php-and-ajax/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.