有人可以告诉我如何从URL中获取youtube id,无论URL中有哪些其他GET变量.
以此视频为例:http://www.youtube.com/watch?v=C4kxS1ksqtw&feature=related
所以v=在下一个之间和之前&
我有一个用户可以写任何东西的文本域.
例如:
Lorem Ipsum只是虚拟文本. http://www.youtube.com/watch?v=DUQi_R4SgWo 印刷和排版行业.自16世纪以来,Lorem Ipsum一直是业界标准的虚拟文本,当时一台未知的打印机采用了类型的厨房,并将其拼凑成一本类型的样本.它不仅存在了五个世纪,而且还延续了电子排版,基本保持不变. http://www.youtube.com/watch?v=A_6gNZCkajU&feature=relmfu 它在20世纪60年代推出了包含Lorem Ipsum段落的Letraset表格,最近还发布了包括Lorem Ipsum版本在内的Aldus PageMaker等桌面出版软件.
现在我想解析它并查找所有YouTube视频网址及其ID.
知道它是如何工作的吗?
我们以这些网址为例:
这个PHP函数不会在案例1中正确获取ID,但是在案例2中.案例1非常常见,其中任何内容都可以在YouTube ID后面.
/**
* get YouTube video ID from URL
*
* @param string $url
* @return string YouTube video id or FALSE if none found.
*/
function youtube_id_from_url($url) {
$pattern =
'%^# Match any YouTube URL
(?:https?://)? # Optional scheme. Either http or https
(?:www\.)? # Optional www subdomain
(?: # Group host alternatives
youtu\.be/ # Either youtu.be,
| youtube\.com # or youtube.com
(?: # Group path alternatives
/embed/ # Either /embed/
| /v/ # or …Run Code Online (Sandbox Code Playgroud) <?php echo $videoFirstArray['fileToUpload']; ?>
Run Code Online (Sandbox Code Playgroud)
该字段包含 ifrmae,类似这样
<iframe width="560" height="315" src="https://www.youtube.com/embed/ISMzgunUono" frameborder="0" allowfullscreen></iframe>
Run Code Online (Sandbox Code Playgroud)
由此我想要这个“ISMzgunUono”。我搜索了论坛并点击了链接,但没有找到任何方法将我的“fileToUpload”字段保留在预匹配中。我关注的一些链接: Get YouTube video id from embed iframe code ,此链接给出了一个错误 how to get Video id from iframe of youtube in php or cakephp 期待很快回复: