尝试在我的文本中替换youtube网址以嵌入。我做对了,除了我还要打印文本" https://www.youtube.com"在嵌入之前。 我该怎么做才能改变?
return preg_replace(
'#(http://(www.)?youtube.com)?/(v/|watch\?v\=)([-|~_0-9A-Za-z]+)&?.*?#i',
'<iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/embed/$4" frameborder="0" allowfullscreen></iframe>',
$text
);
答案 0 :(得分:0)
尝试使用此正则表达式:
return preg_replace(
'/((http(s)?:\/\/)?(www.)?youtube.com\/watch\?v=.*)/i',
'<iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/embed/$4" frameborder="0" allowfullscreen></iframe>',
$text
);