RegEx pattern to get the YouTube video ID from any YouTube URL

后端 未结 9 2024
南方客
南方客 2020-11-27 17:48

Let\'s take these URLs as an example:

  1. http://www.youtube.com/watch?v=8GqqjVXhfMU&feature=youtube_gdata_player
  2. http://www.youtube.com/watch?v=8Gqqj
9条回答
  •  佛祖请我去吃肉
    2020-11-27 18:32

    Instead of regex. I hightly recommend parse_url() and parse_str():

    $url = "http://www.youtube.com/watch?v=8GqqjVXhfMU&feature=youtube_gdata_player";
    parse_str(parse_url( $url, PHP_URL_QUERY ), $vars );
    echo $vars['v'];    
    

    Done

提交回复
热议问题