Connecting and Extracting data from XML/RSS data source
Moderator: General Moderators
-
mariocirillo
- Forum Newbie
- Posts: 8
- Joined: Wed Jun 03, 2009 2:58 pm
Connecting and Extracting data from XML/RSS data source
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
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
Last edited by mariocirillo on Wed Jun 03, 2009 3:34 pm, edited 1 time in total.
Re: Connecting and Extracting data from XML/RSS data source
What have you tried so far?
Re: Connecting and Extracting data from XML/RSS data source
Magpie is generally the best in my experience. It's dead easy to use:
http://magpierss.sourceforge.net/
http://magpierss.sourceforge.net/
Re: Connecting and Extracting data from XML/RSS data source
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.
There is also SimplePie, but I personally haven't implemented it yet.
-
mariocirillo
- Forum Newbie
- Posts: 8
- Joined: Wed Jun 03, 2009 2:58 pm
Re: Connecting and Extracting data from XML/RSS data source
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
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>";
}
?>
Last edited by Benjamin on Tue Jun 09, 2009 11:45 am, edited 1 time in total.
Reason: Changed code type from text to php.
Reason: Changed code type from text to php.
Re: Connecting and Extracting data from XML/RSS data source
hardcode it or loop through 5 times using a for-loop
-
mariocirillo
- Forum Newbie
- Posts: 8
- Joined: Wed Jun 03, 2009 2:58 pm
Re: Connecting and Extracting data from XML/RSS data source
any chance someone can help me to get the for loop to work, ive tried but i keep getting errors.
sorry,
mario
sorry,
mario
Re: Connecting and Extracting data from XML/RSS data source
Show us your code and the errors
-
mariocirillo
- Forum Newbie
- Posts: 8
- Joined: Wed Jun 03, 2009 2:58 pm
Re: Connecting and Extracting data from XML/RSS data source
sorry 
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
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>";
}
}
?>
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
Last edited by Benjamin on Tue Jun 09, 2009 5:11 pm, edited 1 time in total.
Reason: Changed code type from text to php.
Reason: Changed code type from text to php.
-
mariocirillo
- Forum Newbie
- Posts: 8
- Joined: Wed Jun 03, 2009 2:58 pm
Re: Connecting and Extracting data from XML/RSS data source
its ok worked it out now!
I missed out a ; after $coumt = 0
Grrr!
Thankyou for your help guys
I missed out a ; after $coumt = 0
Grrr!
Thankyou for your help guys
-
mariocirillo
- Forum Newbie
- Posts: 8
- Joined: Wed Jun 03, 2009 2:58 pm
Re: Connecting and Extracting data from XML/RSS data source
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
Any ideas? or advise on what i need to change so as not to use DOM?
Thanks
MArio