Enclosure Support for lastRSS
A brief search for a lightweight RSS parser for PHP led me to lastRSS. It supports caching and character encoding -- major plusses for the project I was working on. Unfortunately, lastRSS lacks decent support for enclosures, which was a show stopper for me. I also considered MagpieRSS, which I've heard good things about, but development on the 2.0 version (which purports to support RSS enclosures) seems to have stalled -- the developer hasn't posted an update since last Fall, and the link to the development version was broken.
lastRSS is a pretty clean chunk of code, and extending it to provide support for XML attributes (in turn, supporting the enclosure element) seemed like the simplest option.
Note that this modified version of the code will return an array of attributes, for RSS elements that contain them. If the element also has content, this will be stored in an array element named value.
For example, you can see the output of the script, parsing this feed from Blip.tv:
Array
(
[encoding] => UTF-8
[title] => - blip.tv (beta)
[link] => http://blip.tv
[description] => blip.tv (beta)
[language] => en-us
[lastBuildDate] => Wednesday
[items] => Array
(
[0] => Array
(
[title] => Alternative Networked Public Sphere
[link] => http://blip.tv/file/158685
[description] =>
[category] => Videoblogging
[comments] => http://blip.tv/file/158685
[enclosure] => Array
(
[url] => http://blip.tv/file/get/Cmediachange-AlternativeNetworkedPublicSphere281.mov
[length] => 17280243
[type] => video/quicktime
)
[guid] => Array
(
[value] => D882342A-C756-11DB-AB20-C93374569571
[isPermaLink] => false
)
[pubDate] => Wednesday
)
[ ... ]
I'm pretty sure the script would choke on nested elements, like image, but this is just a quick and dirty fix.
| Attachment | Size |
|---|---|
| lastRSS-attribute.php.txt | 9.24 KB |
- 1155 reads


modification of lastRSS
Hi Peter!
Your code is clean and efficient!
I was wondering if you could help me.
This has nothing to do with your code by the way.
I am having trouble parsing the tag into Smarty because Smarty uses it's own tagging system and therefore the colun ":" becomes a problem.
Would it be possible to parse the attribute and export its contents to a new tag called attribute?
That way I don't have to worry about the colun when I'm calling it.
Thanks so much for reading!
-Ray
editing the comment above
Hi Peter,
Your commenting system stripped out bracketed tags... so basically the above post doesn't make sense!
Basically I'm having trouble with the "content:encoded" into Smarty because uses its own tagging system and therefore the colun ":" in "content:encoded" becomes a problem.
Would it be possible to parse the "content:encoded" attribute in an RSS feed and export it to a new attribute called "content_encoded" for example?
That way I won't have to worry about the colun when I want to call the "content:encoded" tag.
Hopefully that made some sense!
Thanks again for reading!
-Ray
Big Thanx from Japan
Your script solve my problem :)
Thank you so much!!
Please help
How can i public the url in enclosure tag?
is it like this? $item[enclosure]
Thanks
Thanks from France !
Hi Peter,
Thanks for your modification my problem is solve, have more time for some other one now :-).
About last post, how to access to enclosure / url informations, just use $item['enclosure']['url']
Jeff
Re:
halloween costumes | halloween costume
Thank you man
You guy are great. Thanks
sikko
Thanks from Ukraine :)
Thank you!
Post new comment