【发布时间】:2011-03-24 12:11:12
【问题描述】:
有人可以告诉我如何从 url 中获取 youtube id,而不管 URL 中还有哪些其他 GET 变量。
以该视频为例:http://www.youtube.com/watch?v=C4kxS1ksqtw&feature=related
所以在v= 和下一个& 之前
【问题讨论】:
-
你应该看看我的代码github.com/lingtalfi/video-ids-and-thumbnails/blob/master/…,我提供了从youtube、vimeo和dailymotion中提取id的函数。
-
@ling 在函数 getVideoThumbnailByUrl() 中您使用的是 Vimeo 已弃用的 file_get_contents()。这种替换适用于任何地方:
$ch=curl_init(); curl_setopt($ch, CURLOPT_URL, "http://vimeo.com/api/v2/video/$id.php"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); $hash =unserialize(curl_exec($ch)); curl_close($ch); -
@ling 同样在 getYoutubeId($url) 中,最终条件将接受任何字符串并将其验证为 YT id。我将它传递给“垃圾”,它返回垃圾作为从该字符串解析的 id。
-
@jerrygarciuh:afaik file_get_contents 未被弃用,如果您对此功能有疑问,请随时在 github 上报告问题。感谢您发现 getYoutubeId 中的错误(我对其进行了增强)。