pseud Posted August 3, 2012 Share Posted August 3, 2012 I wrote a small PHP script to parse an RSS feed, but it's giving results that are 1 day old, even though the latest one on the RSS feed is around 5 hours old. Could you say what I'm doing wrong please? Here is the RSS feed: http://gumclan.org?action=.xml;type=rss Here is the page of mine that has the script behind it: http://gumclan.org/pseud/ And here is the code: http://pastebin.com/iLfKAqrW Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/266647-new-to-php-need-help-parsing-an-rss-feed/ Share on other sites More sharing options...
pseud Posted August 3, 2012 Author Share Posted August 3, 2012 Sorry, but no replies so I'm bumping. Hope there's no rule against it Quote Link to comment https://forums.phpfreaks.com/topic/266647-new-to-php-need-help-parsing-an-rss-feed/#findComment-1366667 Share on other sites More sharing options...
pseud Posted August 6, 2012 Author Share Posted August 6, 2012 Please can someone help me here? I need this to work! Quote Link to comment https://forums.phpfreaks.com/topic/266647-new-to-php-need-help-parsing-an-rss-feed/#findComment-1367069 Share on other sites More sharing options...
PFMaBiSmAd Posted August 6, 2012 Share Posted August 6, 2012 People are not going to visit sites/links you put in your post just to see your code or to see what the input data is or what the wrong output is. Post your code in the forum's bbcode tags, post an example of the input data, post the resulting output that corresponds to that data, and identify exactly what is wrong with that output. Quote Link to comment https://forums.phpfreaks.com/topic/266647-new-to-php-need-help-parsing-an-rss-feed/#findComment-1367071 Share on other sites More sharing options...
pseud Posted August 6, 2012 Author Share Posted August 6, 2012 Okay - I'll do that. This is the RSS feed: <?xml version="1.0" encoding="ISO-8859-1"?> <rss version="0.92" xml:lang="en-US"> <channel> <title>Grand United Military</title> <link>http://gumclan.org/index.php</link> <description><![CDATA[Live information from Grand United Military]]></description> <item> <title>Re: Low Land Lions vs Fnatic.MSI</title> <link>http://gumclan.org/index.php?topic=1452.msg14412#msg14412</link> <description><![CDATA[<div class="quoteheader"><div class="topslice_quote"><a href="http://gumclan.org/index.php?topic=1452.msg14411#msg14411">Quote from: Furial on <strong>Today</strong> at 11:08:08 AM</a></div></div><blockquote class="bbc_standard_quote"><div class="quoteheader"><div class="topslice_quote"><a href="http://gumclan.org/index.php?topic=1452.msg14410#msg14410">Quote from: BeastR on <strong>Today</strong> at 11:05:15 AM</a></div></div><blockquote class="bbc_alternate_quote"><div class="quoteheader"><div class="topslice_quote"><a href="http://gumclan.org/index.php?topic=1452.msg14406#msg14406">Quote from: fryz0 on <strong>Today</strong> at 10:20:26 AM</a></div></div><blockquote class="bbc_standard_quote">[quote author=BeastR link=topic=1452....</blockquote><div class="quotefooter"><div class="botslice_quote"></div></div></blockquote><div class="quotefooter"><div class="botslice_quote"></div></div></blockquote><div class="quotefooter"><div class="botslice_quote"></div></div>]]></description> <author>lurtz833@hotmail.com</author> <category><![CDATA[Multimedia]]></category> <comments>http://gumclan.org/index.php?action=post;topic=1452.0</comments> <pubDate>Mon, 06 Aug 2012 10:27:09 GMT</pubDate> <guid>http://gumclan.org/index.php?topic=1452.msg14412#msg14412</guid> </item> <item> <title>Re: Low Land Lions vs Fnatic.MSI</title> <link>http://gumclan.org/index.php?topic=1452.msg14411#msg14411</link> <description><![CDATA[<div class="quoteheader"><div class="topslice_quote"><a href="http://gumclan.org/index.php?topic=1452.msg14410#msg14410">Quote from: BeastR on <strong>Today</strong> at 11:05:15 AM</a></div></div><blockquote class="bbc_standard_quote"><div class="quoteheader"><div class="topslice_quote"><a href="http://gumclan.org/index.php?topic=1452.msg14406#msg14406">Quote from: fryz0 on <strong>Today</strong> at 10:20:26 AM</a></div></div><blockquote class="bbc_alternate_quote"><div class="quoteheader"><div class="topslice_quote"><a href="http://gumclan.org/index.php?topic=1452.msg14400#msg14400">Quote from: BeastR on <strong>Today</strong> at 06:04:42 AM</a></div></div><blockquote class="bbc_standard_quote">noob teams specially lighters all bi...</blockquote><div class="quotefooter"><div class="botslice_quote"></div></div></blockquote><div class="quotefooter"><div class="botslice_quote"></div></div></blockquote><div class="quotefooter"><div class="botslice_quote"></div></div>]]></description> <author>furial2_robin@live.nl</author> <category><![CDATA[Multimedia]]></category> <comments>http://gumclan.org/index.php?action=post;topic=1452.0</comments> <pubDate>Mon, 06 Aug 2012 10:08:08 GMT</pubDate> <guid>http://gumclan.org/index.php?topic=1452.msg14411#msg14411</guid> </item> <item> <title>Re: Low Land Lions vs Fnatic.MSI</title> <link>http://gumclan.org/index.php?topic=1452.msg14410#msg14410</link> <description> <![CDATA[<div class="quoteheader"><div class="topslice_quote"><a href="http://gumclan.org/index.php?topic=1452.msg14406#msg14406">Quote from: fryz0 on <strong>Today</strong> at 10:20:26 AM</a></div></div><blockquote class="bbc_standard_quote"><div class="quoteheader"><div class="topslice_quote"><a href="http://gumclan.org/index.php?topic=1452.msg14400#msg14400">Quote from: BeastR on <strong>Today</strong> at 06:04:42 AM</a></div></div><blockquote class="bbc_alternate_quote">noob teams specially lighters all big noobs bait each other 0 skill cheters<br /></blockquote><div class="quotefooter"><div class="botslice_quote"></div></div><br />fnatic.MSI may bey noob...</blockquote><div class="quotefooter"><div class="botslice_quote"></div></div>]]> </description> <author>lurtz833@hotmail.com</author> <category><![CDATA[Multimedia]]></category> <comments>http://gumclan.org/index.php?action=post;topic=1452.0</comments> <pubDate>Mon, 06 Aug 2012 10:05:15 GMT</pubDate> <guid>http://gumclan.org/index.php?topic=1452.msg14410#msg14410</guid> </item> <item> <title>Re: What song are you listening to right now?</title> <link>http://gumclan.org/index.php?topic=591.msg14408#msg14408</link> <description><![CDATA[<embed src="http://www.youtube.com/v/vPVlGWhk0LA&rel=1&fs=1" type="application/x-shockwave-flash" allowFullScreen="true" allowScriptAccess="never" wmode="transparent" width="425px" height="350px"><noembed><a href="http://www.youtube.com/watch?v=vPVlGWhk0LA" target="_blank">http://www.youtube.com/watch?v=vPVlGWhk0LA</a></noembed></embed>]]></description> <author>furial2_robin@live.nl</author> <category><![CDATA[Music]]></category> <comments>http://gumclan.org/index.php?action=post;topic=591.0</comments> <pubDate>Mon, 06 Aug 2012 10:03:14 GMT</pubDate> <guid>http://gumclan.org/index.php?topic=591.msg14408#msg14408</guid> </item> <item> <title>Re: Low Land Lions vs Fnatic.MSI</title> <link>http://gumclan.org/index.php?topic=1452.msg14407#msg14407</link> <description> <![CDATA[<div class="quoteheader"><div class="topslice_quote"><a href="http://gumclan.org/index.php?topic=1452.msg14406#msg14406">Quote from: fryz0 on <strong>Today</strong> at 10:20:26 AM</a></div></div><blockquote class="bbc_standard_quote"><div class="quoteheader"><div class="topslice_quote"><a href="http://gumclan.org/index.php?topic=1452.msg14400#msg14400">Quote from: BeastR on <strong>Today</strong> at 06:04:42 AM</a></div></div><blockquote class="bbc_alternate_quote">noob teams specially lighters all big noobs bait each other 0 skill cheters<br /></blockquote><div class="quotefooter"><div class="botslice_quote"></div></div><br />fnatic.MSI may bey noob...</blockquote><div class="quotefooter"><div class="botslice_quote"></div></div>]]> </description> <author>furial2_robin@live.nl</author> <category><![CDATA[Multimedia]]></category> <comments>http://gumclan.org/index.php?action=post;topic=1452.0</comments> <pubDate>Mon, 06 Aug 2012 10:00:16 GMT</pubDate> <guid>http://gumclan.org/index.php?topic=1452.msg14407#msg14407</guid> </item> </channel> </rss> This is what the page shows Recent Topics Title: Re: Promod map overview. Category: General Promod Talk Link: Re: Promod map overview. Publish date: Mon, 06 Aug 2012 06:59:47 GMT Title: Re: Promod map overview. Category: General Promod Talk Link: Re: Promod map overview. Publish date: Sun, 05 Aug 2012 19:38:02 GMT Title: Re: Promod map overview. Category: General Promod Talk Link: Re: Promod map overview. Publish date: Sun, 05 Aug 2012 15:02:23 GMT Title: Re: Promod map overview. Category: General Promod Talk Link: Re: Promod map overview. Publish date: Sun, 05 Aug 2012 12:53:53 GMT Title: Re: Promod map overview. Category: General Promod Talk Link: Re: Promod map overview. Publish date: Sun, 05 Aug 2012 12:52:45 GMT And this is the script <h3>Recent Topics</h3> <?php //Set new DOMDocument and load the RSS feed with it. $doc = new DOMDocument(); $doc->load('http://gumclan.org?action=.xml;type=rss'); //Set count variable to limit amount of items shown with RSS //$i = 0; //For each <item> in the RSS feed: foreach($doc->getElementsByTagName('item') as $docItem) { //Fill up an array with all of the written tags $docArray = array( 'title' => $docItem->getElementsByTagName('title')->item(0)->nodeValue, 'link' => $docItem->getElementsByTagName('link')->item(0)->nodeValue, 'category' => $docItem->getElementsByTagName('category')->item(0)->nodeValue, 'pubDate' => $docItem->getElementsByTagName('pubDate')->item(0)->nodeValue ); //Display the information in chosen format echo('Title: ' . $docArray['title'] . '<br /> Category: ' . $docArray['category'] . '<br /> Link: <a href="' . $docArray['link'] . '">' . $docArray['title'] . '</a><br /> Publish date: ' . $docArray['pubDate'] . '<br /><br />'); /* //Increment $i $i++; //If $i passes >2, stop the loop. This will stop it at 3 items if ($i > 2) {break;}*/ } Quote Link to comment https://forums.phpfreaks.com/topic/266647-new-to-php-need-help-parsing-an-rss-feed/#findComment-1367103 Share on other sites More sharing options...
Barand Posted August 6, 2012 Share Posted August 6, 2012 From the feed data you gave I get this (dates and titles as in the data) Title: Re: Low Land Lions vs Fnatic.MSI Category: Multimedia Link: http://gumclan.org/index.php?topic=1452.msg14412#msg14412 Pub Date: Mon, 06 Aug 2012 10:27:09 GMT Title: Re: Low Land Lions vs Fnatic.MSI Category: Multimedia Link: http://gumclan.org/index.php?topic=1452.msg14411#msg14411 Pub Date: Mon, 06 Aug 2012 10:08:08 GMT Title: Re: Low Land Lions vs Fnatic.MSI Category: Multimedia Link: http://gumclan.org/index.php?topic=1452.msg14410#msg14410 Pub Date: Mon, 06 Aug 2012 10:05:15 GMT Title: Re: What song are you listening to right now? Category: Music Link: http://gumclan.org/index.php?topic=591.msg14408#msg14408 Pub Date: Mon, 06 Aug 2012 10:03:14 GMT Title: Re: Low Land Lions vs Fnatic.MSI Category: Multimedia Link: http://gumclan.org/index.php?topic=1452.msg14407#msg14407 Pub Date: Mon, 06 Aug 2012 10:00:16 GMT from this code $xml = simplexml_load_file('rss1.xml'); foreach($xml->xpath('//item') as $i) { echo " Title: $i->title Category: $i->category Link: $i->link Pub Date: $i->pubDate\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/266647-new-to-php-need-help-parsing-an-rss-feed/#findComment-1367118 Share on other sites More sharing options...
pseud Posted August 6, 2012 Author Share Posted August 6, 2012 Oh okay, thanks, DOMDocument isn't working properly then. Cheers, I'll do it your way (EDIT) Wait, something's wrong here - not sure what. I'm still getting old results, even with your method. What could be causing this? It's the same in both Chrome and Firefox Quote Link to comment https://forums.phpfreaks.com/topic/266647-new-to-php-need-help-parsing-an-rss-feed/#findComment-1367119 Share on other sites More sharing options...
PFMaBiSmAd Posted August 6, 2012 Share Posted August 6, 2012 I'm still getting old results Exactly what are you getting (we cannot help with anything unless you show us what exactly it is) and have you confirmed if the rss data at the specific time the problem occurred is correct or not? I'm going to guess that your input data is incorrect, possibly because of the php time zone setting vs the time zone where you and your browser are at. Quote Link to comment https://forums.phpfreaks.com/topic/266647-new-to-php-need-help-parsing-an-rss-feed/#findComment-1367150 Share on other sites More sharing options...
pseud Posted August 6, 2012 Author Share Posted August 6, 2012 I'm still getting old results Exactly what are you getting (we cannot help with anything unless you show us what exactly it is) and have you confirmed if the rss data at the specific time the problem occurred is correct or not? I'm going to guess that your input data is incorrect, possibly because of the php time zone setting vs the time zone where you and your browser are at. Aha, that would make sense actually, do you know how I can work around that? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/266647-new-to-php-need-help-parsing-an-rss-feed/#findComment-1367156 Share on other sites More sharing options...
PFMaBiSmAd Posted August 6, 2012 Share Posted August 6, 2012 Not until you actually identify where and what the problem is. So far, you haven't even stated what it is about the date and/or the items being displayed that leads you to believe that they are not correct. Are the date and items wrong or is the date correct, but the items are from the previous day? Quote Link to comment https://forums.phpfreaks.com/topic/266647-new-to-php-need-help-parsing-an-rss-feed/#findComment-1367160 Share on other sites More sharing options...
pseud Posted August 6, 2012 Author Share Posted August 6, 2012 The results on my script are from the previous day whereas the ones on the actual XML file are more recent, I said in my first post Quote Link to comment https://forums.phpfreaks.com/topic/266647-new-to-php-need-help-parsing-an-rss-feed/#findComment-1367163 Share on other sites More sharing options...
Barand Posted August 6, 2012 Share Posted August 6, 2012 Surely in this case the pubDate is just a string and not dependent on zone settings. Even the titles you had in your results don't match the RSS data you posted! Quote Link to comment https://forums.phpfreaks.com/topic/266647-new-to-php-need-help-parsing-an-rss-feed/#findComment-1367187 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.