这是一个简单的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>
请任何人都可以解决问题。我正在尝试不同的方法,但是它们没有用。任何建议将不胜感激。
答案 0 :(得分:0)
感谢大家的建议,我找到了问题。这是因为
标签还存储在链接中,因此未显示视频。在这里:
foreach ($splittedstring as $key => $value) {
$x[$key] = $value."<br>"; //Here was the issue
}
现在这样:
foreach ($splittedstring as $key => $value) {
$x[$key] = $value; //Corrected
}