Advertisement
Guest User

Untitled

a guest
Dec 29th, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. function get_youtube_video_id($video_id)
  2. {
  3.  
  4. // Did we get a URL?
  5. if ( FALSE !== filter_var( $video_id, FILTER_VALIDATE_URL ) )
  6. {
  7.  
  8. // http://www.youtube.com/v/abcxyz123
  9. if ( FALSE !== strpos( $video_id, '/v/' ) )
  10. {
  11. list( , $video_id ) = explode( '/v/', $video_id );
  12. }
  13.  
  14. // http://www.youtube.com/watch?v=abcxyz123
  15. else
  16. {
  17. $video_query = parse_url( $video_id, PHP_URL_QUERY );
  18. parse_str( $video_query, $video_params );
  19. $video_id = $video_params['v'];
  20. }
  21.  
  22. }
  23.  
  24. return $video_id;
  25.  
  26. }
  27.  
  28. $link = "http://www.youtube.com/watch?v=oHg5SJYRHA0";
  29. $video_id = explode("?v=", $link);
  30. $video_id = $video_id[1];
  31.  
  32. $link = "http://www.youtube.com/watch?v=oHg5SJYRHA0&lololo";
  33. $video_id = explode("?v=", $link); // For videos like http://www.youtube.com/watch?v=...
  34. if (empty($video_id[1]))
  35. $video_id = explode("/v/", $link); // For videos like http://www.youtube.com/watch/v/..
  36.  
  37. $video_id = explode("&", $video_id[1]); // Deleting any other params
  38. $video_id = $video_id[0];
  39.  
  40. (?v=|/v/)([-a-zA-Z0-9]+)
  41.  
  42. function youtubeID($url){
  43. $res = explode("v",$url);
  44. if(isset($res[1])) {
  45. $res1 = explode('&',$res[1]);
  46. if(isset($res1[1])){
  47. $res[1] = $res1[0];
  48. }
  49. $res1 = explode('#',$res[1]);
  50. if(isset($res1[1])){
  51. $res[1] = $res1[0];
  52. }
  53. }
  54. return substr($res[1],1,12);
  55. return false;
  56. }
  57. $url = "http://www.youtube.com/watch/v/y40ND8kXDlg";
  58. echo youtubeID($url1);
  59.  
  60. $parts = explode('=', $link);
  61.  
  62. // $parts[1] will y40ND8kXDlg
  63.  
  64. preg_match("#([wd-]){11}#is", 'http://www.youtube.com/watch?v=y40ND8kXDlg', $matches);
  65. echo $matches[1];
  66.  
  67. $link = 'http://www.youtube.com/watch?v=oHg5SJYRHA0&player=normal';
  68.  
  69. strtok($link, '?');
  70.  
  71. parse_str(strtok(''));
  72.  
  73. echo $v;
  74.  
  75. Function getYouTubeID($URL){
  76. $YouTubeCheck = preg_match('![?&]{1}v=([^&]+)!', $URL . '&', $Data);
  77. If($YouTubeCheck){
  78. $VideoID = $Data[1];
  79. }
  80. Return $VideoID;
  81. }
  82.  
  83. If(preg_match('![?&]{1}v=([^&]+)!', $URL . '&', $Data)){
  84. $VideoID = $Data[1];
  85. }
  86.  
  87. function getID_youtube($url)
  88. {
  89. parse_str(parse_url($url, PHP_URL_QUERY), $ID_youtube);
  90. return $ID_youtube['v'];
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement