Jump to content

(new to php) Need help parsing an RSS feed


pseud

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;}*/
}

Link to comment
Share on other sites

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";
}

Link to comment
Share on other sites

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 :o

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.