Skip to content

Instantly share code, notes, and snippets.

@ChrisLTD
Created February 1, 2014 23:39
Show Gist options
  • Save ChrisLTD/8760815 to your computer and use it in GitHub Desktop.
Save ChrisLTD/8760815 to your computer and use it in GitHub Desktop.
Put in a youtube URL of just about any format and get back the ID
<?php
function parse_youtube_url($url){
$id = '';
preg_match("/^.*(youtu.be\\/|v\\/|u\\/\\w\\/|embed\\/|watch\\?v=|\\&v=)([^#\\&\\?]*).*/uism", $url, $matches);
if( isset($matches[2]) ){
$id = $matches[2];
}
return $id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment