Skip to content

Instantly share code, notes, and snippets.

@wwdboer
Created December 21, 2012 16:14
Show Gist options
  • Save wwdboer/4353758 to your computer and use it in GitHub Desktop.
Save wwdboer/4353758 to your computer and use it in GitHub Desktop.
PHP: Get YouTube ID from URL
<?php
function get_ytid( $url ) {
preg_match( "#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $url, $matches );
return $matches[0];
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment