php 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
realtime158
Forum Newbie
Posts: 14
Joined: Mon Nov 20, 2006 9:09 pm

php RSS

Post by realtime158 »

I was wondering i am really struggling with this. Want i want to do is read a RSS feed and grab all the links and output them as a string. I Am using PHP 4.4.4.

Thanks...
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

There are a few XML parsers available for and built-in to PHP. You should check the documentation and look into them.

Also, if ALL you want are the links, it maybe be simpler to use regex. Otherwise.. XML Parser!
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

SimplePie is delicious
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

For parsing XML in PHP 4 your have a choice of DOM XML, which is crap, or SAX, which is crap. You can google for tutorials on either of these (you'll probably be able to find ones specific to RSS in fact), I'd probably go with SAX because at least that isn't a bastardized implementation and the RSS data structure is pretty simple.

PHP 5 has much better implementation of DOM as well as the very popular SimpleXML.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

The problem with parsing RSS feeds with inbuilt abstraction libraries is having to deal with the syntactical variations across different versions of RSS, and writing extra code to deal with Atom if need be. A library like SimplePie does all the work for you.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

You make a good point. But that library looks really bloated and personally I won't touch anything without very good unit test coverage.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

You're right: it is a little hefty, includes caching support and a lot of other junk you probably wouldn't use. It's fairly modular though, so you probably won't incur the extra bloat if you don't use it.

realtime158: If you have a very specific application for the RSS parser, you might just write your own as ole suggested.
Post Reply