Display RSS Image with SimplePie

1.6k Views Asked by At

I'm setting up a page which grabs the first entry from multiple RSS feeds. I'm running into a lot of RSS feeds that are formated differently. I'm using SimplePie to parse the feeds. The current feed I'm trying to grab the image from is below:

<entry>
<updated>2011-01-28T09:00:00Z</updated>
<title><![CDATA[Information on Title of Product]]></title>
<link href="http://link-to-website"/>
<summary type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<img src="http://image.JPG"/>
<div>Title of Image</div>
</div>
</summary>
</entry>

How can I grab the img tag from within the summary tag with SimplePie so I can display this on my website?

Thanks in advance.

1

There are 1 best solutions below

1
On

You will have to grab the content from with SimplePie, and then run it through and XML parser (such as SimpleXML, to get the node you want). For example:

$summary = <<<XML
<div xmlns="http://www.w3.org/1999/xhtml">
    <img src="http://image.JPG"/>
    <div>Title of Image</div>
</div>
XML;

$xml = new SimpleXMLElement($summary);
$imageSrc = (string) $xml->img->attributes()->src;

Didn't use SimpleXML for quite some time, but it should be something like that.