View Full Version : Help Needed Parsing A YouTube Feed with Magpie RSS

02-24-2007, 12:39 AM
Hey guys,

I've stumbled here because this forum seems dedicated to coding and this question is more advanced than other forums I'm part of. So I hope people can help me out.

Let me break down the problem.


Go to http://popurls.com/ and scan down to the heading YouTube. I'm trying to create a similar type of look for my site. Now I have no problems with formating and getting the title from this RSS feed:



The only problem is trying to extract the Thumbnail URL from the RSS feed

This is in the description of the item:

<img src="http://sjl-static6.sjl.youtube.com/vi/JOKvxnaC9KU/2.jpg" align="right" border="0" width="120" height="90" vspace="4" hspace="4" />
<p>i made this cos i was bored but in the end enjoyed it</p>
<p>Author: <a href="http://youtube.com/profile?user=samraimi">samraimi</a><br/>
Keywords: <a href="/results?search_query=resident">resident</a> <a href="/results?search_query=evil">evil</a> <a href="/results?search_query=zombie">zombie</a><br/>
Added: February 23, 2007<br/>

Notice the thumbnail URL is: http://sjl-static6.sjl.youtube.com/vi/JOKvxnaC9KU/2.jpg.

If i just extract the description I get all the garbage in the description which I don't want. I just want to extract the URL and then once I do that I know how to create an image with it in PHP.

But how do I extract this URL. It's driving me nuts. :)


02-24-2007, 01:46 PM
Why not just convert the feed to array, then you can get what you want by just calling $array[#]['description']['image']. XML in PHP is that bright, it uses more regex based handling than true XML object handling. So converting to an array is always better, because PHP(s) array handler is super fast compared to it's current implementation of handling XML.



download example