Web Hosting Talk







View Full Version : RSS parser dont recognize <enclosure


danyboy2010
01-08-2007, 03:51 AM
Hello

I have a script that use http://lastrss.oslab.net/lastRSS.phps to parse content

The problem is that dont recognize <enclosure tag .Can take images
only from <image> tag

var $channeltags = array ('title', 'link', 'description', 'language', 'copyright', 'managingEditor', 'webMaster', 'lastBuildDate', 'rating', 'docs');
var $itemtags = array('title', 'link', 'description', 'author', 'category', 'comments', 'enclosure', 'guid', 'pubDate', 'source','image', 'thumb');
var $imagetags = array('title', 'url', 'link', 'width', 'height');
var $textinputtags = array('title', 'description', 'name', 'link');


// Parse IMAGE info
preg_match("'<image.*?>(.*?)</image>'si", $rss_content, $out_imageinfo);
if (isset($out_imageinfo[1])) {
foreach($this->imagetags as $imagetag) {
$temp = $this->my_preg_match("'<$imagetag.*?>(.*?)</$imagetag>'si", $out_imageinfo[1]);
if ($temp != '') $result['image_'.$imagetag] = $temp; // Set only if not empty
}

I think here is the problem preg_match("'<image.*?>(.*?)</image>'si", $rss_content, $out_imageinfo);

Can somebody help me so i can make it to take the images from <enclosure tag too ?


<item><title>Title</title><link>http://link</link><pubDate>Date</pubDate><description>Description</description><category>Category</category><enclosure url="http://www.site.com/images/img.jpg" type="image/jpeg" length="10000" /></item>

Saeven
01-08-2007, 12:04 PM
You just want to extract the image from the XML's enclosure tag using a regular expression?

danyboy2010
01-08-2007, 07:23 PM
Yeah this is what i wanna do

Saeven
01-08-2007, 07:33 PM
You can match the text inside of the enclosure image specification with this regular expression:


#\<enclosure url="(.*?)"#is


You can use PHP's preg_match for example to actually perform the task