By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,714 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,714 IT Pros & Developers. It's quick & easy.

Q: How do I parse values from a RSS feed?

P: n/a
If I have an RSS newsfeed like this:

<?xml version="1.0" encoding="utf-8"?><!-- generator="whocares" -->
<rss version="0.92">
<channel>
<title>Website Name</title>
<link>http://www.websiteurl.com</link>
<description>Description of website</description>
<lastbuilddate>Sun, 19 Sep 2004 04:34:52 +0000</lastbuilddate>
<docs>http://backend.userland.com/rss092</docs>

<item>
<title>1st Title</title>
<description>1st Description</description>
<link>http://www.websiteurl.com/1stlink/</link>
</item>

<item>
<title>2nd Title</title>
<description>2nd Description</description>
<link>http://www.websiteurl.com/2ndlink/</link>
</item>
</channel>
</rss>

And the following code is used to parse that file/feed:

<?php
$feed = 'http://www.example.com/feed/rss/';

/* ...create and XML parser... */
$xml_parser = xml_parser_create();

/* ...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);

/* ...free parser */
xml_parser_free( $xml_parser );
?>

How do I extract the values from $xml_parser?

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

How about: http://pear.php.net/package/XML_RSS
Charles Stricklin wrote:
If I have an RSS newsfeed like this:

<?xml version="1.0" encoding="utf-8"?><!-- generator="whocares" -->
<rss version="0.92">
<channel>
<title>Website Name</title>
<link>http://www.websiteurl.com</link>
<description>Description of website</description>
<lastbuilddate>Sun, 19 Sep 2004 04:34:52 +0000</lastbuilddate>
<docs>http://backend.userland.com/rss092</docs>

<item>
<title>1st Title</title>
<description>1st Description</description>
<link>http://www.websiteurl.com/1stlink/</link>
</item>

<item>
<title>2nd Title</title>
<description>2nd Description</description>
<link>http://www.websiteurl.com/2ndlink/</link>
</item>
</channel>
</rss>

And the following code is used to parse that file/feed:

<?php
$feed = 'http://www.example.com/feed/rss/';

/* ...create and XML parser... */
$xml_parser = xml_parser_create();

/* ...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);

/* ...free parser */
xml_parser_free( $xml_parser );
?>

How do I extract the values from $xml_parser?

Jul 17 '05 #2

P: n/a
On Sun, 19 Sep 2004 22:33:40 -0500, "Charles Stricklin"
<ch**************@bellsouth.net> wrote:
If I have an RSS newsfeed like this:

How do I extract the values [...]


Not answering directly, but look up MagpieRSS, it's simpler and has some nice
RSS-specific features.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.