any suggestions on xml feed?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

any suggestions on xml feed?

Post by saumya »

i am a beginner of php and just now i started walking on php.Now i think i should make an xml reader.CAn i make that if yes how.I mean i want to get the rss feed from one site and read that and put that in my local pc.When i open my local site, it should read that xml feed and show it to me. how to go about it?
thanks for the guidance.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Have a look at this thread: viewtopic.php?t=36972
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

thanks a lot.
I will go through the link and let you know about the doubts.
thanks
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

i tried that class but my browser does not say anything.
myReader.php

Code: Select all

<?php
include_once("studyParser.php");
$xml= new parser("http://www.mozilla.org/reorganization/feed.xml","XMLbasetag","XMLelement"); 
?>
any idea why? I am behind a firewall and got user id and password to access remote sites.I am guessing that is the problem, but can not figureout how to go about it.
thanks
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

saumya wrote:i tried that class but my browser does not say anything.
myReader.php

Code: Select all

<?php
include_once("studyParser.php");
$xml= new parser("http://www.mozilla.org/reorganization/feed.xml","XMLbasetag","XMLelement"); 
?>
any idea why? I am behind a firewall and got user id and password to access remote sites.I am guessing that is the problem, but can not figureout how to go about it.
thanks
You need to replace "XMLbasetag" and "XMLelement" with the xml basetag and the XML base element.

For RSS try

Code: Select all

$rssFeed =new parser("http://www.mozilla.org/reorganization/feed.xml","ITEM","RSS");
to see the output use

Code: Select all

echo'<H3>_$rssFeed->result</H3><XMP>';print_r($rssFeed->result);echo'</XMP>';
Btw. parsing an RSS feed with PHP is not quite "walking", it's more "jogging": a semi-advanced topic. The script I posted on that thread is document according to phpDocumentor - see if you can understand what it's actually doing - which, if you want to learn about PHP, is what you should do anyway.
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

no luck here too.
Can u give me the code which exactly out puts the mozilaa rss feed i gave preveously.So that if it works, i can go on and study what exactly should be done to read such type of files?
asking too much but can not help,My browser does not show up anyything now.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

using the code I've posted above

Code: Select all

include_once("class_xml_parser.inc.php");
$rssFeed =new parser("http://www.mozilla.org/reorganization/feed.xml","ITEM","RSS");
echo'<H3>_$rssFeed->result</H3><XMP>';print_r($rssFeed->result);echo'</XMP>';
yields:
XML parsing result wrote: <H3>_$rssFeed->result</H3><XMP>Array
(
[-1] => Array
(
[TITLE] => Mozilla Foundation Reorganization
[LINK] => http://www.mozilla.org/reorganization/
[DESCRIPTION] => Blog links and posts related to the Mozilla Foundation's recent reorganization announcement.
)

[0] => Array
(
[TITLE] => Interview with Mitchell Baker at OSCON 2005 (Audio)
[DESCRIPTION] => MP3 podcast of interview with Mitchell Baker, President, Mozilla Corporation recorded at OSCON 2005.
[PUBDATE] => Thu, 04 Aug 2005 12:49:00 -0800
[LINK] => http://ftp.mozilla.org/pub/mozilla.org/ ... n-2005.mp3
)

[1] => Array
(
[TITLE] => Chris Blizzard - Mozilla Corporation
[DESCRIPTION] => Chris Blizzard, Board Member, Mozilla Corporation
[LINK] => http://www.0xdeadbeef.com/html/2005/08/#200508032005
[PUBDATE] => Wed, 03 Aug 2005 16:27:00 -0800
)

[2] => Array
(
[TITLE] => Tristan Nitot - Mozilla Foundation Reorganization
[DESCRIPTION] => Tristan Nitot, President, Mozilla Europe
[LINK] => http://standblog.org/blog/2005/08/03/93 ... ganization
[PUBDATE] => Wed, 02 Aug 2005 23:59:00 -0800
)

[3] => Array
(
[TITLE] => Karim Lakhani - Organizational Innovation: The Mozilla Corporation
[DESCRIPTION] => Karim Lakhani, Open Source Researcher, MIT
[LINK] => http://spoudaiospaizen.net/archives/200 ... rporation/
[PUBDATE] => Wed, 02 Aug 2005 23:59:00 -0800
)

[4] => Array
(
[TITLE] => Frank Hecker - The Mozilla Foundation Reorganization
[DESCRIPTION] => Frank Hecker, Director of Policy, Mozilla Foundation
[LINK] => http://www.hecker.org/mozilla/dot-reorg/
[PUBDATE] => Tue, 02 Aug 2005 23:59:00 -0800
)

[5] => Array
(
[TITLE] => Mitchell Baker - Organizing the Mozilla Project: Mozilla Corporation
[DESCRIPTION] => Mitchell Baker, President, Mozilla Corporation and Board Member, Mozilla Foundation
[LINK] => http://weblogs.mozillazine.org/mitchell ... the_1.html
[PUBDATE] => Tue, 02 Aug 2005 23:59:00 -0800
)

)
</XMP>
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

why my page does not show anything? i am doing something nonsense or missing out something :( :(

Code: Select all

<?php
include_once("class_xml_parser.inc.php");
$rssFeed =new parser("http://www.mozilla.org/reorganization/feed.xml","ITEM","RSS");
echo'<H3>_$rssFeed->result</H3><XMP>';print_r($rssFeed->result);echo'</XMP>'; 
?>
this does not show up anything.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

add

Code: Select all

error_reporting (E_ALL);
at the top of the file from where you include the class, run it and post the result.
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

now my file lloks like this

Code: Select all

<?php
error_reporting (E_ALL); 
include_once("class_xml_parser.inc.php");
$rssFeed =new parser("http://www.mozilla.org/reorganization/feed.xml","ITEM","RSS");
echo'<H3>_$rssFeed->result</H3><XMP>';print_r($rssFeed->result);echo'</XMP>'; 
?>
but still browser is empty
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

you don't seem to be getting the rss-feed. Try

Code: Select all

$fp = fopen($file, "r");
while($data=fread($fp,4096)){
        $xml[]=$data;
}
echo'<H3>_$xml</H3><XMP>';print_r($xml);echo'</XMP>';
This checks whether the script is receiving the feed.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

I've found http://magpierss.sf.net very useful :)

But you might want to solve your fetching remote data first... Meaby you ('re webhost) has been blocked by mozilla website because you fetch the file too many times in a given timeslot..
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

oops, replace $file with "http://www.mozilla.org/reorganization/feed.xml" in the first line of the script I posted above:

Code: Select all

$fp = fopen("http://www.mozilla.org/reorganization/feed.xml", "r");
I am behind a firewall and got user id and password to access remote sites.
That might be the problem. Ask your IT-deparment how to run scripts fetching remote data.
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

Code: Select all

<?php
//checking for feed
$file="http://www.mozilla.org/reorganization/feed.xml";
$fp = fopen($file, "r");
while($data=fread($fp,4096)){
        $xml[]=$data;
}
echo'<H3>_$xml</H3><XMP>';
print_r($xml);
echo'</XMP>';
?>
Now my code is that, but without result.I think the problem is with the getting the data from net.
But then how the rss readers such as thunderbird gets data?!!
thanks a lot
Post Reply