Saturday, 27 December 2014

how to fetch image path from description element in RSS



Hello Sir I am trying to fetch image path from amazon RSS feeds but there are 3 different images in the description tag...I am using DOMDocument method to fetch data from RSS feeds ...When i am trying to fetch the image path its fetching the complete description(all 3 images path in one), but i only need 1st main image path to show it in my RSS feed slider... need help badly ...last date of project submission ...Thanks in advanced


Amazon RSS feed -- http://www.amazon.co.uk/gp/rss/bestsellers/electronics/560834/ref=zg_bs_560834_rsslink


And Here is my test code to check images are working or not



error_reporting(0);
$rss = new DOMDocument();
$rss->load('http://www.amazon.co.uk/gp/rss/bestsellers/electronics/560834/ref=zg_bs_560834_rsslink');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
'img' => $node->getElementsByTagName('description')->item(1)->getAttribute('src')
);
array_push($feed, $item);
}
$limit = 10;
for($x=0;$x<$limit;$x++) {
$title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
$link = $feed[$x]['link'];
$description = $feed[$x]['desc'];
$img = $feed[$x]['img'];
$date = date('l F d, Y', strtotime($feed[$x]['date']));

echo $img;
echo "<hr/>";
}

No comments:

Post a Comment