【发布时间】:2011-12-09 02:33:28
【问题描述】:
function youtube($string)
{
preg_match('#(v\/|watch\?v=)([\w\-]+)#', $string, $match);
return preg_replace(
'#((http://)?(www.)?youtube\.com/watch\?[=a-z0-9&_]+)#i',
"<div align=\"center\"><iframe title=\"YouTube video player\" width=\"480\" height=\"390\" src=\"http://www.youtube.com/embed/$match[2]\" frameborder=\"0\" allowfullscreen></iframe></div>",
$string);
}
这个函数几乎可以工作,但是由于“&”字符变成了“&”它并没有完全摆脱整个 URL。
http://www.youtube.com/watch?v=oRcUzu_xdJI&feature=feedu
例如返回
嵌入式视频&feature=feedu
我需要如何修改第二个正则表达式?
#((http://)?(www.)?youtube\.com/watch\?[=a-z0-9&_]+)#i
【问题讨论】: