Skip to content

Instantly share code, notes, and snippets.

@vlepeule
Created October 3, 2016 15:36
Show Gist options
  • Save vlepeule/1f09cc75b96f3d23f73e0f185cdedc07 to your computer and use it in GitHub Desktop.
Save vlepeule/1f09cc75b96f3d23f73e0f185cdedc07 to your computer and use it in GitHub Desktop.
Get youtube video ID from URL (regex)
<?php
$url = "http://your_youtube_video_url";
preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $url, $matches);
echo $matches[1]; // The ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment