Tero

[+] Youtube ID regex

May 3rd, 2018
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. // http://youtu.be/dQw4w9WgXcQ
  2. // http://www.youtube.com/embed/dQw4w9WgXcQ
  3. // http://www.youtube.com/watch?v=dQw4w9WgXcQ
  4. // http://www.youtube.com/?v=dQw4w9WgXcQ
  5. // http://www.youtube.com/v/dQw4w9WgXcQ
  6. // http://www.youtube.com/e/dQw4w9WgXcQ
  7. // http://www.youtube.com/user/username#p/u/11/dQw4w9WgXcQ
  8. // http://www.youtube.com/sandalsResorts#p/c/54B8C800269D7C1B/0/dQw4w9WgXcQ
  9. // http://www.youtube.com/watch?feature=player_embedded&v=dQw4w9WgXcQ
  10. // http://www.youtube.com/?feature=player_embedded&v=dQw4w9WgXcQ
  11.  
  12. // It also works on the youtube-nocookie.com URL with the same above options.
  13. // It will also pull the ID from the URL in an embed code (both iframe and object tags)
  14.  
  15. preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match);
  16. $youtube_id = $match[1];
Advertisement
Add Comment
Please, Sign In to add comment