Get Vimeo ID from URL / API

<? /* You may want to use oEmbed discovery instead of hard-coding the oEmbed endpoint. */ $oembed_endpoint = 'http://vimeo.com/api/oembed'; // Grab the video url $video_url = 'http://vimeo.com/7100569'; // Create the URLs $xml_url = $oembed_endpoint . '.xml?url=' . rawurlencode($video_url) . '&width=640'; // Curl helper function function curl_get($url) { $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_TIMEOUT, 30); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); $return = curl_exec($curl); curl_close($curl); return $return; } // Load in the oEmbed XML $oembed = simplexml_load_string(curl_get($xml_url)); /* An alternate approach would be to load JSON, then use json_decode() to turn it into an array. */ ?> <?php echo $oembed->title ?> <?php echo $oembed->video_id ?>

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.