Skip to content

Instantly share code, notes, and snippets.

@bpierre
Created August 23, 2011 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpierre/1164929 to your computer and use it in GitHub Desktop.
Save bpierre/1164929 to your computer and use it in GitHub Desktop.
Parse video providers
<?php
// From Robbie Player: https://forrst.com/posts/Grab_Youtube_or_Vimeo_Info_with_PHP-0el#comment-150356
function video_url_to_id($url, $provider) {
$video_id = FALSE;
$url = parse_url($url);
switch ($provider) {
case 'youtube':
$vid = parse_str($url['query'], $output);
$video_id = $output['v'];
break;
case 'vimeo':
$video_id = str_replace("/", "", $url['path']);
break;
}
return $video_id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment