$这 - > youtube-> getUserUploads();
如何从URL中提取VideoID
是否有任何方法可以调用?
有什么建议吗?
答案 0 :(得分:0)
我在任何地方都找到了这个功能......也许它会有所帮助。
public 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 /v/
| .*v= # or /watch\?v=
) # End path alternatives.
) # End host alternatives.
([\w-]{10,12}) # Allow 10-12 for 11 char youtube id.
($|&).* # if additional parameters are also in query string after video id.
$%x';
$result = preg_match($pattern, $url, $matches);
if (false !== $result) {
return isset($matches[1]) ? $matches[1] : false;
}
return false;
}