Nathan Riley
asked on
RSS Feed Parsing for Images
I'm trying to parse out an RSS feed for images. My original code grabbed the title, description, link, and pubDate just fine. I read a tutorial online on how to get the images out as well, but now that I've updated my pull it gives me the errror:
Fatal error: Call to a member function getAttribute() on a non-object in /home/ode/public_html/dev/ cron-insig hts2.php on line 10
Here is my code:
Fatal error: Call to a member function getAttribute() on a non-object in /home/ode/public_html/dev/
Here is my code:
<?php
$rss = new DOMDocument();
$rss->load('http://feeds.feedburner.com/feedburner/Dvzy?format=xml');
$feed = array();
//FOR EACH ITEM RETURN RSS
foreach ($rss->getElementsByTagName('item') as $node) {
$img = $rss->getElementsByTagName('img')->item(0)->getAttribute('src');
$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,
'image' => $img,
);
array_push($feed, $item);
}
echo '<pre>';
var_dump($feed);
echo '</pre>';
ASKER
Perfect, thanks Ray!
How can I have the image field only grab the first image as the image value instead of an array of them all?
How can I have the image field only grab the first image as the image value instead of an array of them all?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great, thanks!
Glad to help!
https://iconoun.com/demo/temp_gallitin.php
Open in new window