PHP>无法按功能嵌入 youtube 视频

发布于 2024-11-14 17:38:55 字数 911 浏览 4 评论 0原文

我不知道我的嵌入脚本出了什么问题,按照我的逻辑,它应该正确地将视频嵌入到框架中,但它加载的是 www.youtube.com 的框架视图而不是我的视频视频。

单个目录中有 2 个文件:

ClassMedia.php:

 <?php
class Media {

    public function embedYT($code){
        echo "<iframe width='560' height='349' src='http://www.youtube.com/embed/".$code." frameborder='0' allowfullscreen></iframe>";
        }}

Demo.php:

    <?php include "classMedia.php"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Demo</title>
</head>

<body>

<?php 
$media = new Media();
 $code = "XSGBVzeBUbk";
$media-> embedYT($code);
?>
</body>
</html>

I don't know what's wrong with my embed script, to my logic it should properly embed the video in the frame, but it loads a framed view of www.youtube.com instead of my video video.

There are 2 files in a single directory:

ClassMedia.php:

 <?php
class Media {

    public function embedYT($code){
        echo "<iframe width='560' height='349' src='http://www.youtube.com/embed/".$code." frameborder='0' allowfullscreen></iframe>";
        }}

Demo.php:

    <?php include "classMedia.php"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Demo</title>
</head>

<body>

<?php 
$media = new Media();
 $code = "XSGBVzeBUbk";
$media-> embedYT($code);
?>
</body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨轻弹 2024-11-21 17:38:55

您在 src='http://www.youtube.com/embed/".$code." 之后缺少一个单引号,您需要这样:

echo "<iframe width='560' height='349' src='http://www.youtube.com/embed/".$code."' frameborder='0' allowfullscreen></iframe>";

请注意添加的单引号。

YouTube 最终会看到一个错误的网址(http://www.youtube.com/embed/$code frameborder=,其中 $code 是真实的代码)并为您提供主页而不是您认为您要求的内容。

You're missing a single quote right after src='http://www.youtube.com/embed/".$code.", you want this:

echo "<iframe width='560' height='349' src='http://www.youtube.com/embed/".$code."' frameborder='0' allowfullscreen></iframe>";

Note the added single quote.

YouTube ends up seeing a bad URL (http://www.youtube.com/embed/$code frameborder= where $code is the real code) and hands you the homepage instead of what you think you were asking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文