jdubwelch Posted February 3, 2008 Share Posted February 3, 2008 I've got a script that reads RSS feeds and shows them. Some show the xml file, some don't. I'm totally stumped as to why it doesn't. At first I thought it wouldn't reed RSS version 2.0 files, but I tried different ones and some worked. So that wasn't it. This is the xml file i'm trying to read in. If I save this file on my own server link to it directly it WORKS! However, if i link to the actual file on whatever server it's on, nothing shows up. I know i have the right link, i copied it right from my RSS feed program and if i paste it into my web browser it brings up the feed. The link to the actual xml file is: http://rgweb-c.registerguard.com/blogs/index.php/ducksbkn/rss_2.0/ This is the xml file: <?xml version="1.0" encoding="utf-8"?> <rss version="2.0" xmlns:ng="http://newsgator.com/schema/extensions" xmlns:wfw="http://wellformedweb.org/CommentAPI/"> <channel> <title>Duck Men's Basketball with Bob Clark</title> <link>http://rgweb-c.registerguard.com/blogs/index.php/ducksbkn</link> <copyright>Copyright retained by original author, refer to http://rgweb-c.registerguard.com/blogs/index.php/ducksbkn/rss_2.0/ for further information</copyright><description /> <webMaster>support@newsgator.com</webMaster> <lastBuildDate>2008-02-02T21:53:31</lastBuildDate><image><url /> <title>Duck Men's Basketball with Bob Clark</title> <link>http://rgweb-c.registerguard.com/blogs/index.php/ducksbkn</link></image> <ng:id>1790546</ng:id><ttl>60</ttl> <ng:token>MDIyMDA4LTAyLTAyVDIxOjUzOjMxLjEzMCA0MjkyMTI3NDIz</ng:token> <item> <title>Moving up the lists in Civil War</title> <link>http://rgweb-c.registerguard.com/blogs/index.php/ducksbkn/commentsmoving_up_the_lists_in_civil_war/</link> <description><p>OK, who breaks their skid? </p> <p> Oregon has lost four in a row, Oregon State it’s last 10 games. </p></description> <guid isPermaLink="false">tag:newsgator.com,2006:Feed.aspx/1790546/4292127318</guid> <pubDate>Sun, 03 Feb 2008 01:23:43 GMT</pubDate> <ng:modifiedDate>Sat, 02 Feb 2008 18:23:44 GMT</ng:modifiedDate> <ng:postId>4292127318</ng:postId> <ng:read>False</ng:read> <author>bclark@guardnet.com</author> <ng:avgRating>0.000000</ng:avgRating> <ng:clipped>False</ng:clipped> </item> <item> <title>Oregon pulls away from Beavers, 79-63</title> <link>http://rgweb-c.registerguard.com/blogs/index.php/ducksbkn/commentsoregon_pulls_away_from_beavers_79_63/</link> <description><p>Oregon went on a three-point spree to break away from a one-point lead as the Ducks continued their mastery over Oregon State at McArthur Court with a 79-63 victory Saturday. </p> <p> In winning the Civil War at home for the 15th consecutive year, the Ducks (13-8, 4-5 in the Pac-10) also halted their own four-game losing streak. The Beavers (6-15, 0-9) lost their 10th consecutive game and reached the midpoint of their Pac-10 schedule still winless. </p></description> <guid isPermaLink="false">tag:newsgator.com,2006:Feed.aspx/1790546/4292127423</guid> <pubDate>Sun, 03 Feb 2008 01:23:43 GMT</pubDate> <ng:modifiedDate>Sat, 02 Feb 2008 18:23:44 GMT</ng:modifiedDate> <ng:postId>4292127423</ng:postId> <ng:read>True</ng:read> <author>bclark@guardnet.com</author> <ng:avgRating>0.000000</ng:avgRating> <ng:clipped>False</ng:clipped> </item> </channel> </rss> Here's my php code do display xml RSS Feeds: <?php function readXML($file){ // Read in XML from URL into variable $xml $filePointer = fopen($file,"r") or die("Could not connect to the rss file"); while(!feof($filePointer)){ $xml .= fread($filePointer,1024); } fclose($filePointer); return $xml; } function startTag($parser,$tag,$attributes){ // Process XML Opening Tags global $rssBlockLocation; global $rssCurrentTag; if($tag == "CHANNEL"){ $rssBlockLocation = "CHANNEL"; } elseif ($tag == "ITEM") { $rssBlockLocation = "ITEM"; } $rssCurrentTag = $tag; } function endTag($parser,$tag){ // Process XML Closing Tags global $rssBlockLocation; global $rssItemArray; global $rssTempItem; if($rssBlockLocation == "ITEM" && $tag == "ITEM"){ $rssItemArray[] = $rssTempItem; $rssTempItem = ""; } } function characterData($parser,$characterData){ // Process XML Character Data global $rssBlockLocation; global $rssCurrentTag; global $rssChannelArray; global $rssTempItem; if($rssCurrentTag == "TITLE" || $rssCurrentTag == "LINK" || $rssCurrentTag == "DESCRIPTION"){ if($rssBlockLocation == "CHANNEL"){ $rssChannelArray[$rssCurrentTag] .= $characterData; } elseif($rssBlockLocation == "ITEM"){ $rssTempItem[$rssCurrentTag] .= $characterData; } } } // Set up Variables to keep track of the position in the XML $rssBlockLocation = ""; $rssCurrentTag = ""; // Set up Variables to hold the data extracted from the XML $rssChannelArray = ""; $rssTempItem = ""; $rssItemArray = ""; // Read in the XML $url = "http://rgweb-c.registerguard.com/blogs/index.php/ducksbkn/rss_2.0/"; $xml = readXML($url); // Parse the XML $parser = xml_parser_create(); xml_set_element_handler($parser,"startTag","endTag"); xml_set_character_data_handler($parser,"characterData"); if(!xml_parse($parser,$xml)){ $error = xml_error_string($xml_ger_error_code($parser)); $line = xml_get_current_line_number($parser); die("XML Error: " . $error . " at line number " . $line); } xml_parser_free($parser); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>RSS Feed - Macromedia Dreamweaver MX</title> <style type="text/css"> <!-- #rssFeed{ width: 400px; } .channelHeadline{ font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; } .itemDescription{ font-family: Arial, Helvetica, sans-serif; font-size: 12px; } a{ font-family: Arial, Helvetica, sans-serif; font-size: 12px; } a:link{ color: #009900; text-decoration: none; } a:visited{ color:#009900; text-decoration: none; } a:hover{ color:#009900; } a:active{ color:#009900; text-decoration: none; } --> </style> </head> <body> <?php echo "<div id='rssFeed'>"; // Output Channel Header echo "<span class='channelHeadline'>" . $rssChannelArray['TITLE'] . "</span><br />"; echo "<a href='" . $rssChannelArray['LINK'] . "'>" . $rssChannelArray['DESCRIPTION'] . "</a>"; echo "<br />"; // Output Items foreach($rssItemArray as $item){ echo "<hr width='100%' align='left'>"; echo "<a href='" . $item['LINK'] . "'>" . $item['TITLE'] . "</a>"; echo "<br />"; echo "<span class='itemDescription'>" . $item['DESCRIPTION'] . "</span>"; echo "<br />"; } echo "</div>"; ?> </body> </html> If you can help in anyway, I'd be so greatful. Thanks for any help in advance. Quote Link to comment https://forums.phpfreaks.com/topic/89156-im-stumped-problem-reeding-an-rss-feed/ Share on other sites More sharing options...
chwebdesigns Posted March 9, 2008 Share Posted March 9, 2008 Not sure whether you are still interested, but somehow i came across this topic. Have you tried just putting the local link to the feed here? <?php // Read in the XML $url = "http://rgweb-c.registerguard.com/blogs/index.php/ducksbkn/rss_2.0/"; $xml = readXML($url); ?> for example; <?php // Read in the XML $url = "feed.xml"; $xml = readXML($url); ?> I tested it on my Apache 2.2 Server and it worked fine. Not sure whether it would work all of the time though Quote Link to comment https://forums.phpfreaks.com/topic/89156-im-stumped-problem-reeding-an-rss-feed/#findComment-487588 Share on other sites More sharing options...
jdubwelch Posted March 11, 2008 Author Share Posted March 11, 2008 It's not my feed so it's not a local feed. Unless, there's a way to make it local just to load the file temporarily and then get rid of it. Ideas? Quote Link to comment https://forums.phpfreaks.com/topic/89156-im-stumped-problem-reeding-an-rss-feed/#findComment-489159 Share on other sites More sharing options...
tippy_102 Posted March 11, 2008 Share Posted March 11, 2008 I think it's not working because this: $url = "http://rgweb-c.registerguard.com/blogs/index.php/ducksbkn/rss_2.0/"; isn't the actual name of the .xml file. Maybe contact the site owner and see if they will give you the link to the feed file? Quote Link to comment https://forums.phpfreaks.com/topic/89156-im-stumped-problem-reeding-an-rss-feed/#findComment-489232 Share on other sites More sharing options...
jdubwelch Posted March 15, 2008 Author Share Posted March 15, 2008 I'm linking to tons of feeds (lots are having this problem), so i was just trying to make this one work and implement it on the rest. There's so many feeds I probably wont get the actual link to the xml file. How can I read in their feed, and make a temporary xml file on my server to read it, then delete it? Quote Link to comment https://forums.phpfreaks.com/topic/89156-im-stumped-problem-reeding-an-rss-feed/#findComment-492738 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.