【发布时间】:2012-05-08 10:07:19
【问题描述】:
我使用以下代码替换 youtube 网址以嵌入链接,以便将它们显示为视频。但是我遇到了一个问题,我无法从具有更多参数的链接查看视频,而不是 ?v=video_code
php代码:
function embedYoutube($text)
{
$pattern = '|http://www\.youtube\.com/watch\?.*?\bv=([^ ]+)|';
$replacement = '<div style="width:100%;float:left;margin-top:15px;margin-bottom:15px;"><iframe width="570" height="315" src=http://www.youtube.com/embed/$1 frameborder="0" allowfullscreen></iframe></div>';
return preg_replace($pattern, $replacement, $text, 1);
}
【问题讨论】:
标签: php regex preg-replace pattern-matching embed