我有如下文字如何在文本中替換YouTube網址?
"I made this video on my birthday. All of my friends are here in party. Click play to video the video
http://www.youtube.com/watch?v=G3j6avmJU48&feature=g-all-xit "
我想是更換該上述網址可
"I made this video on my birthday. All of my friends are here in party. Click play to video the video
<iframe width="853" height="480" src="http://www.youtube.com/embed/G3j6avmJU48" frameborder="0" allowfullscreen></iframe> "
我知道我們可以從上面的URL獲得YouTube視頻ID在下面的腳本
preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $word, $matches);
$youtube_id = $matches[0];
但我不知道如何替換url
http://www.youtube.com/watch?v=G3j6avmJU48&feature=g-all-xit
到
<iframe width="853" height="480" src="http://www.youtube.com/embed/G3j6avmJU48" frameborder="0" allowfullscreen></iframe>
請幫助謝謝
這是一個[複製](http://stackoverflow.com/questions/1188129/replace-urls-in -text-with-html-links) – Matt 2012-08-01 21:20:42
當它必須從url獲取id並用iframe標記替換url時它是如何複製的?所描述的鏈接只是一個正常的鏈接。 – user1494854 2012-08-01 21:29:19