0

在我的网站上,我正在尝试显示一些 youtube 视频。在数据库中,我有 youtube 视频上的地址,我正试图在我的网站上显示它。问题是当平板电脑访问该网站时,此代码不起作用。

我不知道为什么,也不知道如何调试问题。

<?php    
// url of video
$url = $data['video'];

// we get the unique video id from the url by matching the pattern
preg_match("/v=([^&]+)/i", $url, $matches);
$id = $matches[1];

// template for generating embed codes
$code = '<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/{id}&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/{id}&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>';

// replace each {id} with the actual ID of the video to get embed code
$code = str_replace('{id}', $id, $code);

if(isset($id)&& $id !== '') { 
    echo $code; 
} 
?>

你能帮我一些指点吗?

4

1 回答 1

1

您使用的嵌入代码是超古<object>版本。改用基于 YouTube 的较新<iframe>嵌入,它应该可以在更多移动设备上运行:

$code = '<iframe width="425" height="344" src="http://www.youtube.com/embed/{id}" frameborder="0" allowfullscreen></iframe>';
于 2013-02-24T21:10:02.147 回答