I am trying to pull an rss feed through for the following rss feed http://menmedia.co.uk/manchestereveningnews/news/rss.xml
I can pull this through no problem using this
As far as I can see it, the enclosure is an open-closed tag only consisting of attributes.
<enclosure length="1280" url="http://m.gmgrd.co.uk/res/108.$plit/C_71_article_1469226_short_teaser_group_short_teaser_image.jpg" type="image/jpeg" />
This means, that you cannot just access its values like you do with guid
or title
, but you have to access the attributes.
Currently you do not even set the index you are trying to access later:
$item_array[] = array(
'title' => $title,
'url' => $url,
'description' => $description,
'timestamp' => $timestamp
// Here enclosure is missing
);
I do not know your XML class, but you need to find out, if you can access element attributes after using element_set, somehow. Or if there is another method to access the attributes.
As soon as you know the URL, you can grasp the image from that URL and create a copy on your own server. Both options however cause different problems:
Dependant on which way you’ll go, you will either just call
// $attribute is the url-attribute of the enclosure-tag
<img src="'.$attribute.'">
or copy the image to your own server and then call
<img src="'.$urlToImageOnYourServer.'">
If you are using the functions from bobulous.org.uk and it includes part 3 already, you could edit your foreach-loop like this to get the enclosure url:
foreach($news_items as $item) {
$title = value_in('title', $item);
$url = value_in('link', $item);
$description = value_in('description', $item);
$timestamp = strtotime(value_in('pubDate', $item));
$imageAttrs = attributes_in('enclosure', $item));
$imageUrl = $imageAttrs['url'];
$item_array[] = array(
'title' => $title,
'url' => $url,
'description' => $description,
'timestamp' => $timestamp,
'enclosure' => $imageUrl,
);
}