Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
php get youtube video id from youtube video url
/**
* getYoutubeId
* @par string $video_url
*/
public function getYoutubeId( $url )
{
// http://stackoverflow.com/a/10315969/2252921
preg_match('/^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/', $url, $founded);
return !empty( $founded ) ? $founded[1] : '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment