Reputation: 1940
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
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