homepage Welcome to WebmasterWorld Guest from 54.205.122.62
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / RSS, ATOM, and Related Technologies
Forum Library, Charter, Moderators: bill & werty

RSS, ATOM, and Related Technologies Forum

    
Parseing the <enclosure> URL
How to extract a URL from the <enclosure> tag using magpie
stipko



 
Msg#: 4063138 posted 9:06 pm on Jan 18, 2010 (gmt 0)

I was hopeing someone could help asap.

I am using Magpie RSS. I would like to extract the image URL from the <enclosure> tag in a RSS feed.

Here is the relevant source from the RSS feed that Magpie is parceing:


<enclosure url="http://www.example.com/myphoto.jpg" length="1" type="image/jpeg" />

Here is the relevant code snipit in my php file I am trying to use, to no avail:


echo '<img src="'.$item['enclosure'].'">';

What am I doing wrong?

Thanks in advance for any help!

Aaron

 

whoisgregg

WebmasterWorld Senior Member whoisgregg us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4063138 posted 3:52 pm on Jan 19, 2010 (gmt 0)

Welcome to WebmasterWorld. stipko!

When dealing with parsed XML feeds, I make liberal use of var_dump() [php.net] to figure out where the parser put everything.

In your case, try var_dump($item); to figure out the structure of the array/object. If it turns out Magpie parses XML into an object instead of an array, you have to use a different syntax to get the enclosure value:

echo '<img src="'.$item->enclosure.'">';

stipko



 
Msg#: 4063138 posted 8:33 pm on Jan 19, 2010 (gmt 0)

Thanks for the response Gregg.

I tried the var_dump($item) to figure out the structure of the array/object and the result was this (I truncated some text for this forum):

array(10) {
["title"]=>
string(16) "Avatar"
["link"]=>
string(76) "http://www.example.com/avatar.html"
["description"]=>
string(554) "This movie tops the box office"
["author"]=>
string(23) "affiliates@example.com"
["category"]=>
string(17) "Top 10 Box Office"
["comments"]=>
string(79) "http://www.example.com/avatar.html#comments"
["pubdate"]=>
string(29) "Mon, 18 Jan 2010 04:32:06 GMT"
["source"]=>
string(37) "Example.com Top 10 Box Office Movies"
["summary"]=>
string(554) "This is the summary information"
["date_timestamp"]=>
int(1263789126)
}

The <enclosure...> wasn't referenced in the dump. So even though the image URL exists in the feed:

<enclosure url="http://www.example.com/myphoto.jpg" length="1" type="image/jpeg" />

...I still cant seem to extract it for use in my page. What am I doing wrong?

I am grateful for your time on this. I really appreciate it.

Aaron

ergophobe

WebmasterWorld Administrator ergophobe us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4063138 posted 7:21 am on Jan 20, 2010 (gmt 0)

Welcome stipko!

Way past my bedtime... I'm probably missing something here... ignore if irrelevant.

Just to be sure I've got the problem: when you look at the raw feed, you see the enclosure and the image URL, but for some reason you don't see it in the data as parsed by Magpie.

A few thoughts (as I say, perhaps ill-conceived due to late hour).

1. Based just on your variable name ($item), it looks to me like you're iterating through the $rss->items array and grabbing each as $item and then using var_dump() on that.

Have you checked for a $rss->images array? I think that's where Magpie puts images, but I might be wrong.

In any case, try a var_dump() for the full $rss object before running through it for the individual items.

[edit] not wrong I think
- [bblog.com...]
- [magpierss.sourceforge.net...]
[/edit]

2. Assuming you just can't get the image with Magpie, you have the feed XML right? Why not grab the feed itself grep for the enclosure and get the image that way?

I'm not sure how all the pieces of your app/script/site fit together so I'm not sure if #2 makes any sense or if that means you'll just be processing the feed twice, but it's a possibility.

3. Look into another RSS parser.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / RSS, ATOM, and Related Technologies
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved