Quantcast
Viewing all articles
Browse latest Browse all 16

php: parsing rss feed using simplexml and xpath

I tried to parse the link on rss feed with images using php.

I tried parsing the rss feed to display images from the enclosure tag. I tried the solution given on that link. But it doesn't work. The element_attributes function has not been defined.

So, I tried to get the images using xPath. The following is my output (empty array):

Array()

on my web server error log.

Can anyone point out on where i'm going wrong? Thank you.

<?php
if (function_exists("curl_init")){
    $ch=curl_init();
    curl_setopt($ch,CURLOPT_URL, 'http://menmedia.co.uk/manchestereveningnews/news/rss.xml');
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    //curl_setopt($ch,CURLOPT_HEADER,0);
$data=curl_exec($ch);


curl_close($ch);


$doc=new SimpleXmlElement($data,LIBXML_NOCDATA);

function getImage($xml){
    $imgs=$xml->xPath('rss/channel/enclosure[@attributes]');
    print_r($imgs);
    /*foreach ($imgs as $image){
        echo $image->url;
    }*/
}
if (isset($doc->channel)) getImage($doc);

} ?>


Viewing all articles
Browse latest Browse all 16

Trending Articles