Reading RSS

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
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Reading RSS

Post by tecktalkcm0391 »

Does anybody know of something already build, or something easy to build to read this:

Code: Select all

  <?xml version="1.0" ?> 
- <rss version="2.0">
- <channel>
  <title>Colorado Results from SuperPages.com</title> 
  <link>http://www.superpages.com/cities/CO.html</link> 
  <description>Colorado Results from SuperPages.com: Yellow Pages, White Pages, and Online Directories</description> 
  <language>en-us</language> 
  <pubDate>Mon, 16 Jul 2007 16:35:02 CST</pubDate> 
- <item>
  <title>Results for Saturday, 7/14/07</title> 
  <link>http://www.superpages.com/cities/CO.html</link> 
  <description>The winning results for Saturday, 7/14/07 are: 2, 5, 6, 25, 28. Brought to you by http://www.SuperPages.com. 
  <pubDate>Sat, 14 Jul 2007 23:15:06 CST</pubDate> 
  </item>
- <item>
  <title>Results2 for Saturday, 7/14/07</title> 
  <title>Results2 for Saturday, 7/14/07</title> 
  <link>http://www.superpages.com/cities/CO.html</link> 
  <description>The second winning results for Saturday, 7/14/07 are: 2, 5, 6, 25, 28. Brought to you by http://www.SuperPages.com. 
  <pubDate>Sat, 14 Jul 2007 23:15:23 CST</pubDate> 
  </item>
  </channel>
  </rss>
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

PHP 4 or PHP 5?
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

PHP 5 is fine.
User avatar
mikeeeeeeey
Forum Contributor
Posts: 130
Joined: Mon Jul 03, 2006 4:17 am
Location: Huddersfield, UK

Post by mikeeeeeeey »

Try SimpleXML, it's pretty cool since its so simple (hence the name) to read XML.

Here's something I was playing around with the other day for reading the basic weather information from http://www.theweathernetwork.com/
on their RSS read:

Code: Select all

$xml = simplexml_load_file('http://rss.theweathernetwork.com/weather/gbxx0005');
$dc = $xml->children();
//$article['creator'] = $dc->creator;
echo "<span style=\"font-size: 28px; color: #333333\">" . $dc->channel->title . "</span>";
echo "<br/><br/>";
echo $dc->channel->item->description;
Before anyone gets scared, theres no classes or anything going on there. It really is that simple. The only bits you'll need to mess with are outputting the information, I'm picking specific parts from this since they're all I need.
You may need to output all the feed, or other bits, so look up some schema or some xPath to see what you can do.

Hope it helps
Post Reply