嵌入式youtube视频未通过iframe和php显示

问题描述 投票:0回答:1

这是一个简单的html表单。我正在尝试从用户获取视频链接的同时显示youtube视频。我使用一个输入字段作为链接,用户可以在其中输入来自youtube的视频的链接,这是表格:

<body>
<form action="youtubetest.php" method="post">
    Enter Link here<br><input type="link" name="youtubelink">
    <input type="submit" name="submit">
</form>
</body>

通过此表格,我接受通过邮寄发送至youtubetest.php的链接。这是youtubetest.php:

<!DOCTYPE html> 
<html> 
<body> 
<?php
$str = $_POST['youtubelink'];
$splittedstring = explode("watch?v=",$str);    //For obtaining video id
foreach ($splittedstring as $key => $value) {

$x[$key] = $value."<br>";
}

$link = "https://www.youtube.com/embed/";
$vid_link = $link.$x[1];   //Concatenation
echo "Video Link is : ".$vid_link;
echo "<iframe src='".$vid_link."' allowfullscreen  height='480' width='500'";

 ?>
</body> </html> 

请任何人解决这个问题。我正在尝试不同的方法,但是它们没有用。任何建议将不胜感激。

php html forms iframe youtube-iframe-api
1个回答
0
投票

感谢大家的建议,我找到了问题。这是因为
标签还存储在链接中,因此未显示视频。在这里:

foreach ($splittedstring as $key => $value) {


 $x[$key] = $value."<br>";  //Here was the issue


 }

现在像这样:

 foreach ($splittedstring as $key => $value) {


 $x[$key] = $value; //Corrected


 }
© www.soinside.com 2019 - 2024. All rights reserved.