Jonathan
Jonathan

Reputation: 683

Getting Img Tag from RSS Description

I currently have a couple of RSS feeds which hide their images within the pesky description tag.

I'm trying to get only the image src from the description, but I seem to be failing with every solution on here.

<description><![CDATA[Duration: 604 sec<br>URL: http://www.test.com/videos/998879/surf.mpeg<br><img src="http://test.test.com/320x240/461/1055458.jpg"><br><iframe src="http://test.com/embed/998879" frameborder=0 width=650 height=518 scrolling=no></iframe>]]></description>

As you can see it's a bit stuck in there!

function echo_url($string) {
preg_match_all('#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', $string, $match);
return $match[0][0];
}

Currently using this function to try and retrieve the image but no luck!

Any help would be brilliant!

Upvotes: 1

Views: 1116

Answers (1)

Kyle
Kyle

Reputation: 1733

$description = '<description><![CDATA[Duration: 604 sec<br>URL: http://www.test.com/videos/998879/surf.mpeg<br><img src="http://test.test.com/320x240/461/1055458.jpg"><br><iframe src="http://test.com/embed/998879" frameborder=0 width=650 height=518 scrolling=no></iframe>]]></description>';
$html = str_get_html($description);
echo $html->find('img', 0)->src;

http://simplehtmldom.sourceforge.net/

Upvotes: 1

Related Questions