Warren Winters Warren Winters - 4 months ago 14
PHP Question

RSS XML show itunes:image url in PHP

Hello I need some help getting the image URL of the itunes:image attribute from my XML rss feed. I can retrieve everything else in the array, but not 'mainimg'. The current code returns nothing for the image although it's there. Do you have any idea how I can do this, I'm looking for the HREF so I can place it inside 'img' tags.

$doc = new DOMDocument();

foreach ($doc->getElementsByTagName('item') as $node) {
$itemRSS = array (
'maintitle' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
'enclosure' => $node->getElementsByTagName('enclosure')->item(0)->getAttribute('url'),
'mainimg' => $node->getElementsByTagName('image')->item(0)->getAttribute('url')/*This is what I'm trying to call the itunes:image attribute(HREF) with*/,

<div class="showcontent">
<img src="<?php echo $itemRSS['image']; /*echo the itunes:image attribute(HREF)*/ ?>">
<h2><a href="<?php echo $itemRSS['link']; ?>"><?php echo $itemRSS['title']; ?></a></h2>
<p><strong>Published</strong> <?php echo $itemRSS['date']; ?></p>

<audio controls>
<source src="<?php echo $itemRSS['enclosure']; ?>" type="audio/mpeg">
Your browser does not support the audio element.

<?php $cnt ++; } ?>

// Get namespace URI for prefix `itunes`
echo $ns = $s->lookupNamespaceURI('itunes');
// Get `image` tag from that namespace
echo $href = $node->getElementsByTagNameNS($ns, 'image')->item(0)->getAttribute('href');