Page 1 of 1

Connecting and Extracting data from XML/RSS data source

Posted: Wed Jun 03, 2009 3:08 pm
by mariocirillo
Hello,

Im mario - im new to the forum. Ive come from an ASP background and have only just started to tech myself PHP. So sorry you will have to bare with me. I must admit tho from what ive seen so far im very impressed.

if anyone could help me with the following it would be greatly appriciated.

i have an rss feed from a website:
http://www.fccuk.org/forum/cache/global_rss4.xml

On my php page i would like to display the first 4 tags / posts from the feed. I want to display the title as a hyperlink.

Im not sure how to go about this, ive found a few scripts on the net but have not really been able to work them out.

If anyone can help that would be fantastic,

Many Thanks,
Mario

Re: Connecting and Extracting data from XML/RSS data source

Posted: Wed Jun 03, 2009 3:22 pm
by divito
What have you tried so far?

Re: Connecting and Extracting data from XML/RSS data source

Posted: Wed Jun 03, 2009 5:46 pm
by mikemike
Magpie is generally the best in my experience. It's dead easy to use:
http://magpierss.sourceforge.net/

Re: Connecting and Extracting data from XML/RSS data source

Posted: Wed Jun 03, 2009 6:04 pm
by divito
I second that. I use Magpie for a few different projects and it's really easy and functional.

There is also SimplePie, but I personally haven't implemented it yet.

Re: Connecting and Extracting data from XML/RSS data source

Posted: Mon Jun 08, 2009 4:13 pm
by mariocirillo
thanks guys
i think ive nearly cracked it

my code below displays all of the titles and url, how can i get it to just show the first 5 titles and have them hyperlinked to open in a new window (_blank)

many thanks

Mario

Code: Select all

 
 
<?php
 
  $objDOM = new DOMDocument(); 
  $objDOM->load("http://www.fccuk.org/forum/cache/global_rss4.xml");
 
 
  $item = $objDOM->getElementsByTagName("item"); 
 
 
  foreach( $item as $value ) 
  { 
    $title = $value->getElementsByTagName("title"); 
    $f_title  = $title->item(0)->nodeValue; 
 
 
    $link = $value->getElementsByTagName("link"); 
    $f_link  = $link->item(0)->nodeValue; 
 
    echo "$f_title $f_link <br>"; 
  } 
 
 
?> 
 
 

Re: Connecting and Extracting data from XML/RSS data source

Posted: Mon Jun 08, 2009 7:21 pm
by mikemike
hardcode it or loop through 5 times using a for-loop

Re: Connecting and Extracting data from XML/RSS data source

Posted: Mon Jun 08, 2009 8:19 pm
by mariocirillo
any chance someone can help me to get the for loop to work, ive tried but i keep getting errors.
sorry,

mario

Re: Connecting and Extracting data from XML/RSS data source

Posted: Tue Jun 09, 2009 8:58 am
by mikemike
Show us your code and the errors

Re: Connecting and Extracting data from XML/RSS data source

Posted: Tue Jun 09, 2009 3:07 pm
by mariocirillo
sorry :)

Code: Select all

 
<?php
 
  $objDOM = new DOMDocument(); 
  $objDOM->load("http://www.fccuk.org/forum/cache/global_rss4.xml");
  $item = $objDOM->getElementsByTagName("item"); 
  $coumt = 0
 
  foreach( $item as $value ) 
  { 
    if($count <=5) {
    $title = $value->getElementsByTagName("title"); 
    $f_title  = $title->item(0)->nodeValue; 
    $link = $value->getElementsByTagName("link"); 
    $f_link  = $link->item(0)->nodeValue; 
 
    echo "$f_title $f_link <br>"; 
  }
  } 
 
 
?> 
 
 
the error i get is:

Parse error: parse error in C:\xampp\htdocs\FCCUK\forum.php on line 15

I presume my if statement is causing it as it works fine when i take it out.
THanks for your time and patience.
Mario

Re: Connecting and Extracting data from XML/RSS data source

Posted: Tue Jun 09, 2009 7:08 pm
by mariocirillo
its ok worked it out now!

I missed out a ; after $coumt = 0

Grrr!

Thankyou for your help guys :)

Re: Connecting and Extracting data from XML/RSS data source

Posted: Mon Aug 31, 2009 10:35 am
by mariocirillo
Ive come to upload my site now and been advised i need to try a parser that doesnt use DOM as for somereason when i test it on the live site it just doesnt work. I dont get an error, just a blank space where it should be?

Any ideas? or advise on what i need to change so as not to use DOM?

Thanks

MArio