Skip to content

Instantly share code, notes, and snippets.

@typeoneerror
Created July 14, 2010 02:36
Show Gist options
  • Save typeoneerror/474924 to your computer and use it in GitHub Desktop.
Save typeoneerror/474924 to your computer and use it in GitHub Desktop.
public static function videoIdFromGoogleUrl($source)
{
$pattern = "/^(?:http:\/\/video.google.com\/(?:videoplay|googleplayer.swf)\?docid=([\w\-]+))/is";
$matches = array();
preg_match($pattern, $source, $matches);
if (isset($matches[1])) return $matches[1];
return $source;
}
public static function videoIdFromYoutubeUrl($source)
{
$pattern = "/^(?:http:\/\/(?:www.)?youtube.com\/(?:watch\?v\=|v\/)([\w\-]+))/is";
$matches = array();
preg_match($pattern, $source, $matches);
if (isset($matches[1])) return $matches[1];
return $source;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment