承接 waynestate/parse-youtube-id 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

waynestate/parse-youtube-id

最新稳定版本:1.0.0

Composer 安装命令:

composer require waynestate/parse-youtube-id

包简介

Parse the Video ID from a YouTube URL

README 文档

README

Master Build Status | Coverage Status

Given a YouTube video URL, parse out the video ID.

Usage

Install the package via composer:

composer require waynestate/parse-youtube-id

Parse full YouTube URL's

use Waynestate\Youtube\ParseId;

...

$youtube_id = ParseId::fromUrl('https://www.youtube.com/watch?v=yCjTG0rOIXQ');
echo $youtube_id; // 'yCjTG0rOIXQ'

Parse short YouTube URL's

$youtube_id = ParseId::fromUrl('https://youtu.be/yCjTG0rOIXQ');
echo $youtube_id; // 'yCjTG0rOIXQ'

Null strings or non-YouTube URL's return an empty string

$youtube_id = ParseId::fromUrl('');
echo $youtube_id; // ''

See /tests/UrlParseTest.php for all supported URL variations.

Regex

$pattern = '#^(?:https?://|//)?' # Optional URL scheme. Either http, or https, or protocol-relative.
         . '(?:www\.|m\.)?'      #  Optional www or m subdomain.
         . '(?:'                 #  Group host alternatives:
         .   'youtu\.be/'        #    Either youtu.be,
         .   '|youtube\.com/'    #    or youtube.com
         .     '(?:'             #    Group path alternatives:
         .       'embed/'        #      Either /embed/,
         .       '|v/'           #      or /v/,
         .       '|watch\?v='    #      or /watch?v=,
         .       '|watch\?.+&v=' #      or /watch?other_param&v=
         .     ')'               #    End path alternatives.
         . ')'                   #  End host alternatives.
         . '([\w-]{11})'         # 11 characters (Length of Youtube video ids).
         . '(?![\w-])#';         # Rejects if overlong id.

Tests

composer test

Contributing

See CONTRIBUTING.md for details

Credit

Adapted from Stephan Schmitz at https://3v4l.org/GEDT0

About

Wayne State University (WSU) is an urban public research university located in Detroit, Michigan.

统计信息

  • 总下载量: 71.9k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-14