Possible Duplicate:
How to embed YouTube videos in PHP?
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);
}
This function almost works, but since the "&" character is turned into "&" it doesn't quite get rid of the whole URL.
http://www.youtube.com/watch?v=oRcUzu_xdJI&feature=feedu
For example returns
embedded video&feature=feedu
How would I need to modify the second regex?
#((http://)?(www.)?youtube\.com/watch\?[=a-z0-9&_]+)#i