【发布时间】:2012-01-15 15:10:06
【问题描述】:
我现在正在使用 此代码用于播放 youtube 视频
<?php
// Replace Youtube URLs with embed code
function embedYoutube($text)
{
$search = '% # Match any youtube URL in the wild.
(?:https?://)? # Optional scheme. Either http or https
(?:www\.)? # Optional www subdomain
(?: # Group host alternatives
youtu\.be/ # Either youtu.be,
| youtube\.com # or youtube.com
(?: # Group path alternatives
/embed/ # Either /embed/
| /v/ # or /v/
| /watch\?v= # or /watch\?v=
) # End path alternatives.
) # End host alternatives.
([\w\-]{10,12}) # Allow 10-12 for 11 char youtube id.
\b # Anchor end to word boundary.
%x';
$replace = '<object width="425" height="344">
<param name="movie" value="http://www.youtube.com/v/$1?fs=1"</param>
<param name="allowFullScreen" value="true"></param>
<param name="allowScriptAccess" value="always"></param>
<embed src="http://www.youtube.com/v/$1?fs=1"
type="application/x-shockwave-flash" allowscriptaccess="always" width="425" height="344">
</embed>
</object>';
return preg_replace($search, $replace, $text);
}
$string = 'This is the forum post content with some Youtube links:'."\n".
'http://www.youtube.com/watch?v=NLqAF9hrVbY'."\n".
'http://www.youtube.com/v/u1zgFlCw8Aw?fs=1&hl=en_US';
echo embedYoutube($string);
?>
但这些视频无法以全屏模式播放,而且这些嵌入式代码不显示视频的任何信息或拍摄地点。
例如。 http://www.youtube.com/watch?v=YR12Z8f1Dh8 以全屏选项显示视频 带标题 为什么这个 Kolaveri Di 全歌高清宣传视频 youtube.com
和类似的描述 中国惊喜 观看与音乐作曲家 Anirudh、Dhanush、Shruti Hassan、Aishwarya 和音响工程师 Sivakumar 一起录制歌曲的独家视频
像 facebook 一样。
怎么做,谁有答案。
【问题讨论】:
标签: php html css youtube preg-replace