<i id='FTXvf'><tr id='FTXvf'><dt id='FTXvf'><q id='FTXvf'><span id='FTXvf'><b id='FTXvf'><form id='FTXvf'><ins id='FTXvf'></ins><ul id='FTXvf'></ul><sub id='FTXvf'></sub></form><legend id='FTXvf'></legend><bdo id='FTXvf'><pre id='FTXvf'><center id='FTXvf'></center></pre></bdo></b><th id='FTXvf'></th></span></q></dt></tr></i><div id='FTXvf'><tfoot id='FTXvf'></tfoot><dl id='FTXvf'><fieldset id='FTXvf'></fieldset></dl></div>
      1. <legend id='FTXvf'><style id='FTXvf'><dir id='FTXvf'><q id='FTXvf'></q></dir></style></legend>

        <small id='FTXvf'></small><noframes id='FTXvf'>

      2. <tfoot id='FTXvf'></tfoot>
          <bdo id='FTXvf'></bdo><ul id='FTXvf'></ul>

        获取 youtube 视频 ID 为 PHP

        getting youtube video id the PHP(获取 youtube 视频 ID 为 PHP)
        <tfoot id='lFERe'></tfoot>
        <i id='lFERe'><tr id='lFERe'><dt id='lFERe'><q id='lFERe'><span id='lFERe'><b id='lFERe'><form id='lFERe'><ins id='lFERe'></ins><ul id='lFERe'></ul><sub id='lFERe'></sub></form><legend id='lFERe'></legend><bdo id='lFERe'><pre id='lFERe'><center id='lFERe'></center></pre></bdo></b><th id='lFERe'></th></span></q></dt></tr></i><div id='lFERe'><tfoot id='lFERe'></tfoot><dl id='lFERe'><fieldset id='lFERe'></fieldset></dl></div>
          <tbody id='lFERe'></tbody>

        <legend id='lFERe'><style id='lFERe'><dir id='lFERe'><q id='lFERe'></q></dir></style></legend>
            <bdo id='lFERe'></bdo><ul id='lFERe'></ul>
            1. <small id='lFERe'></small><noframes id='lFERe'>

                  本文介绍了获取 youtube 视频 ID 为 PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前正在编写一个 web 应用程序,其中一些页面严重依赖于能够将正确的 youtube 视频拉入并播放.youtube URL 由用户提供,因此通常会带有变体,其中之一可能如下所示:

                  I am currently writing a webapp in which some pages are heavily reliant on being able to pull the correct youtube video in - and play it. The youtube URLS are supplied by the users and for this reason will generally come in with variants one of them may look like this:

                  http://www.youtube.com/watch?v=y40ND8kXDlg

                  而另一个可能看起来像这样:

                  while the other may look like this:

                  http://www.youtube.com/watch/v/y40ND8kXDlg

                  目前我可以使用以下代码从后者中提取 ID:

                  Currently I am able to pull the ID from the latter using the code below:

                  function get_youtube_video_id($video_id)
                  {
                  
                      // Did we get a URL?
                      if ( FALSE !== filter_var( $video_id, FILTER_VALIDATE_URL ) )
                      {
                  
                          // http://www.youtube.com/v/abcxyz123
                          if ( FALSE !== strpos( $video_id, '/v/' ) )
                          {
                              list( , $video_id ) = explode( '/v/', $video_id );
                          }
                  
                          // http://www.youtube.com/watch?v=abcxyz123
                          else
                          {
                              $video_query = parse_url( $video_id, PHP_URL_QUERY );
                              parse_str( $video_query, $video_params );
                              $video_id = $video_params['v'];
                          }
                  
                      }
                  
                      return $video_id;
                  
                  }
                  

                  如何处理使用 ?v 版本而不是 /v/ 版本的 URL?

                  How can I deal with URLS that use the ?v version rather than the /v/ version?

                  推荐答案

                  像这样:

                  $link = "http://www.youtube.com/watch?v=oHg5SJYRHA0";
                  $video_id = explode("?v=", $link);
                  $video_id = $video_id[1];
                  

                  这是通用的解决方案:

                  $link = "http://www.youtube.com/watch?v=oHg5SJYRHA0&lololo";
                  $video_id = explode("?v=", $link); // For videos like http://www.youtube.com/watch?v=...
                  if (empty($video_id[1]))
                      $video_id = explode("/v/", $link); // For videos like http://www.youtube.com/watch/v/..
                  
                  $video_id = explode("&", $video_id[1]); // Deleting any other params
                  $video_id = $video_id[0];
                  

                  或者只是使用这个正则表达式:

                  Or just use this regex:

                  (?v=|/v/)([-a-zA-Z0-9]+)
                  

                  这篇关于获取 youtube 视频 ID 为 PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <tfoot id='Vssrx'></tfoot>
                • <i id='Vssrx'><tr id='Vssrx'><dt id='Vssrx'><q id='Vssrx'><span id='Vssrx'><b id='Vssrx'><form id='Vssrx'><ins id='Vssrx'></ins><ul id='Vssrx'></ul><sub id='Vssrx'></sub></form><legend id='Vssrx'></legend><bdo id='Vssrx'><pre id='Vssrx'><center id='Vssrx'></center></pre></bdo></b><th id='Vssrx'></th></span></q></dt></tr></i><div id='Vssrx'><tfoot id='Vssrx'></tfoot><dl id='Vssrx'><fieldset id='Vssrx'></fieldset></dl></div>

                    <small id='Vssrx'></small><noframes id='Vssrx'>

                          <tbody id='Vssrx'></tbody>
                        <legend id='Vssrx'><style id='Vssrx'><dir id='Vssrx'><q id='Vssrx'></q></dir></style></legend>
                        • <bdo id='Vssrx'></bdo><ul id='Vssrx'></ul>