我不知道我的嵌入脚本有什么问题,按照我的逻辑,它应该将视频正确地嵌入到框架中,但是它会加载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/