For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > September 2004 > Re: How do I parse values from a RSS feed?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: How do I parse values from a RSS feed?
Janwillem Borleffs

2004-09-21, 8:55 pm

Charles Stricklin wrote:
> If I have an RSS newsfeed like this:

[...]
> And the following code is used to parse that file/feed:

[...]
> /* ...open the feed and parse it... */
> $fp = @fopen($feed, 'rb');
> if (is_resource($fp)) {
> xml_parse_into_struct( $xml_parser, $fp, $vals, $index );
> }
> @fclose($fp);


Read the manual closely and you will notice that the second argument of
xml_parse_into_struct() should be a string, not a resource.

The following would work better:

$file = file_get_contents($feed);

if ($file) {
xml_parse_into_struct( $xml_parser, $file, $vals, $index );
}

> How do I extract the values from $xml_parser?


Again, when you read the manual, you will notice that you don't extract the
values from the resource stored in $xml_parser, but that
xml_parse_into_struct() uses the last two arguments to create an array of
keys and values and an array of indexes which matches the positions of the
elements in the document.

Check the output of print_r() on both arrays to see what I mean.

Please read http://www.php.net/manual/en/ref.xml.php for more info and
examples.


JW



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com