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.

AttachmentSize
lastRSS-attribute.php.txt9.24 KB
Posted In

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

Anonymous | Thu, 2007-11-08 17:20

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

Anonymous | Thu, 2007-11-08 17:23

Big Thanx from Japan

Your script solve my problem :)
Thank you so much!!

Anonymous | Fri, 2008-02-08 04:15

Please help

How can i public the url in enclosure tag?

is it like this? $item[enclosure]

Thanks

Anonymous | Mon, 2008-06-02 11:34

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

Anonymous | Wed, 2008-06-04 12:58
Anonymous | Sat, 2008-08-23 02:44

Thank you man

You guy are great. Thanks
sikko

Anonymous | Tue, 2008-09-09 09:28
Anonymous | Thu, 2008-10-23 16:20

Post new comment

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Images can be added to this post.

More information about formatting options

Captcha
This question is used to make sure you are a human visitor and to prevent spam submissions.
Copy the characters (respecting upper/lower case) from the image.

Flickr Photos

Get Firefox

Random Quote

When a whole nation is roaring Patriotism at the top of its voice, I am fain to explore the cleanness of its hands and purity of its heart.

— Ralph Waldo Emerson
Journals, 1824