1

$this->youtube->getUserUploads();

如何VideoID从 URL 中提取是否有任何方法可以调用?

有什么建议么 ?

4

1 回答 1

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;
}
于 2013-10-28T12:06:05.457 回答