Skip to content

Instantly share code, notes, and snippets.

@ryarwood
Created November 14, 2012 02:45
Show Gist options
  • Save ryarwood/4069977 to your computer and use it in GitHub Desktop.
Save ryarwood/4069977 to your computer and use it in GitHub Desktop.
Extract YouTube ID from url
$link = "http://www.youtube.com/watch?v=oHg5SJYRHA0&lololo";
$video_id = explode("?v=", $link); // For videos like http://www.youtube.com/watch?v=...
if (empty($video_id[1]))
$video_id = explode("/v/", $link); // For videos like http://www.youtube.com/watch/v/..
$video_id = explode("&", $video_id[1]); // Deleting any other params
$video_id = $video_id[0];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment