Saturday 10 September 2016

How to parse XML Youtube Feeds in PHP into array format?

        $ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "gdata.youtube.com/feeds/api/playlists/PL802BE7047AA4DE0E?max-results=50&orderby=published&v=2");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
$xml = simplexml_load_string($output);
$youtubedata = json_decode(json_encode((array)$xml), TRUE);

No comments:

Post a Comment

Your comment is so valuable as it would help me in my growth of knowledge.