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

标签 class function youtube embed media

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

一个目录中有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>

最佳答案

您想在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最终看到错误的URL(http://www.youtube.com/embed/$code frameborder=,其中$code是实际代码),然后将您的主页交给了您,而不是您认为的要求。

关于class - PHP>无法按功能嵌入youtube视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6314184/

相关文章:

c++ - 优化递归函数

python - 使用YouTube API和cron将视频上传到YouTube时的身份验证问题

ios - XCDYouTubeVideoPlayerViewController videoURL为nil

c++ - 编译器如何实现C++继承?

perl - Perl源代码中的 "1;"是什么?

python - 禁止向 Python 子类添加新方法

youtube - 通过Java中的youtube API禁用视频评论

php - 为后期静态绑定(bind)复制函数

JavaScript:使用Reduce()构造一个比较输入数组的函数交集;仅返回相交元素

Python 函数不能在循环内工作