是否有正则表达式可以从youtube视频页面链接中获取youtube嵌入代码?
我希望文字与这个问题相反: Getting youtube links from embedded youtube video on pages?
编辑: 我需要类似以下代码:
public static String GetYoutubeEmbedCode(String YoutubeLink)
{
String SourceLink = /* Something involving YoutubeLink*/;
String YoutubeEmbedCode = "<object width=\"640\" height=\"385\"><param name=\"movie\" value=\"" + SourceLink + "\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"" + SourceLink + "\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"640\" height=\"385\"></embed></object>";
return YoutubeEmbedCode;
}
答案 0 :(得分:2)
有一种新的,更简单的方法来嵌入http://apiblog.youtube.com/2010/07/new-way-to-embed-youtube-videos.html
中描述的YouTube视频如果用户选择使用它,它还支持HTML5播放器。
答案 1 :(得分:1)
基本上你需要类似的东西:
$subject = 'http://www.youtube.com/watch?v=Hy4HAPu7lsc'; // the link
$pattern = '%http://www\.youtube\.com/watch\?v=([A-Za-z0-9]+)%';
$replacement = '<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/$1?fs=1&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/$1?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>';
preg_replace($pattern, $replacement, $subject);