i'm working youtube v3 api. after few tests, realized need help. when i'm trying display xml content, i'm getting null values. can me?
if want see xml:
https://www.youtube.com/feeds/videos.xml?channel_id=$channelid
and code is:
$xml=simplexml_load_file("videos.xml"); foreach($xml $content) { echo $content->title . "<br>"; echo $content->link['href'] . "<br>";
}
xml want display:
<entry> video id <yt:videoid>q4vsza_8kyy</yt:videoid> video title <title>¡trailer del canal! cbprductions</title> upload date <published>2016-01-14t07:37:03+00:00</published> <media:group> description <media:description> porque lo digo yo _ suscribete!: https://www.youtube.com/user/spanishcbproductions dale mi página facebook: https://www.facebook.com/spanishcbproductions sigueme en twitter!: https://twitter.com/ccristiann3 y en mi poco sexy instagram: http://instagram.com/ccristiann3/ </media:description> </media:group> </entry>
i think can register namespace , use xpath. 'media' , 'yt' can children passing namespace.
if want display first entry:
$url = 'https://www.youtube.com/feeds/videos.xml?channel_id=ucrgn72qu0ktti_ujnxrr3fg'; $xml = simplexml_load_file($url); $ns = $xml->getdocnamespaces(true); $xml->registerxpathnamespace('a', 'http://www.w3.org/2005/atom'); $elements = $xml->xpath('//a:entry'); $content = $elements[0]; $yt = $content->children('http://www.youtube.com/xml/schemas/2015'); $media = $content->children('http://search.yahoo.com/mrss/'); echo "video id: " . $yt->videoid . "<br>"; echo "video title: " . $content->title . "<br>"; echo "upload date: " . $content->published . "<br>"; echo "description: " .$media->group->description . "<br>";
if want display information entries, can use:
foreach ($elements $content) { $yt = $content->children('http://www.youtube.com/xml/schemas/2015'); $media = $content->children('http://search.yahoo.com/mrss/'); echo "video id: " . $yt->videoid . "<br>"; echo "video title: " . $content->title . "<br>"; echo "upload date: " . $content->published . "<br>"; echo "description: " . $media->group->description . "<br>"; echo "<br>"; }
Comments
Post a Comment