vespino
vespino

Reputation: 1940

get url attribute of rss feed

I'm looking for a way to get the value of the url attribute with the media:thumbnail tag of this RSS feed.

I currently have this code:

//getNamespaces
$ns=$rss->getNamespaces(true);

foreach($rss->entry as $entry) {
    //set children of namespaces
    $yt=$entry->children($ns['yt']);
    $media=$entry->children($ns['media']);
}

But the media element/object for the tag I want is empty.

I have tried using simplexml attributes without success.

Upvotes: 1

Views: 1469

Answers (1)

The fourth bird
The fourth bird

Reputation: 163642

I think that you can loop the children of $media and then get the attributes() from the thumbnail.

Maybe this setup can help you:

<?php
$url = "https://www.youtube.com/feeds/videos.xml?user=XLLease";
$rss = simplexml_load_file($url);

//getNamespaces
$ns=$rss->getNamespaces(true);

foreach($rss->entry as $entry) {
    //set children of namespaces
    $yt=$entry->children($ns['yt']);
    $media=$entry->children($ns['media']);
    foreach ($media as $value) {
        $url = $value->thumbnail->attributes()->url->__toString();
    }
}

Upvotes: 2

Related Questions