【问题标题】:Displaying youtube video from mysql database using php?使用 php 从 mysql 数据库显示 youtube 视频?
【发布时间】:2017-02-20 09:26:48
【问题描述】:

我想在页面上显示 youtube 视频,以下是我的代码,以便从存储在 mysql 中的数据库中获取 youtube 视频 URL,然后通过使用 while 循环进行迭代来显示它。但是,iframe 不会在其中显示任何视频。

<?php
   if ($get_result != false) {
       while ($row = mysqli_fetch_array($get_result, MYSQLI_ASSOC)) {
?>
          <iframe width="560" height="315" src="<?php echo $row["url"]; ?>" frameborder="0" allowfullscreen></iframe>
<?php
       }
   }
?>

我也尝试在 while 循环中使用视频标签,但它不会在视频播放器中显示 Youtube 视频。 请帮我解决这个问题。

【问题讨论】:

  • 请显示您尝试播放的任何 Youtube 视频 url 值(在您的数据库中)
  • 当我在 chrome 中检查网页时,它显示我的输出为&lt;iframe width="560" height="315" src="https://www.youtube.com/watch?v=txSGdNONUJE" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;
  • 把你的网址改成'youtube.com//v/txSGdNONUJE'就可以了
  • 是的@KiranMuralee,它对我有用,我只是将来自数据库的网址细化如下$new_url = str_replace("https://www.youtube.com/watch?v=","https://www.youtube.com//v/",$url);

标签: php mysql video iframe youtube


【解决方案1】:

你可以使用嵌入的 Youtube,像这样:

<iframe width="560" height="315" src="https://www.youtube.com/embed/<?php echo $row["url"]; ?>?autoplay=1&autohide=1&controls=1&showinfo=0&modestbranding=1&rel=0"></iframe>

【讨论】:

    【解决方案2】:

    问题在于您的网址值。将视频网址中的“"watch?v=”替换为"v/",然后重试。例如我尝试过

    <iframe width="560" height="315" 
    src="https://www.youtube.com//v/txSGdNONUJE" frameborder="0" allowfullscreen></iframe> 
    

    上面的代码可以正常工作。

    【讨论】:

      猜你喜欢
      • 2018-10-15
      • 1970-01-01
      • 2016-01-16
      • 1970-01-01
      • 2018-08-15
      • 1970-01-01
      • 2014-12-19
      • 2014-11-15
      • 1970-01-01
      相关资源
      最近更新 更多