get id video vimeo with regexp preg_match

僤鯓⒐⒋嵵緔 提交于 2019-11-29 08:01:55

Why not ask Vimeo about the video?

http://vimeo.com/api/oembed.json?url=http%3A//vimeo.com/17892962

The above URL will give you a nice JSON response with lots of useful information, including the video ID and appropriate HTML to embed the video in a page. Just pass your URLs to the oEmbed endpoint as shown above.

Example JSON response (truncated long lines for display purposes)

{
    "type": "video",
    "version": "1.0",
    "provider_name": "Vimeo",
    "provider_url": "http://vimeo.com/",
    "title": "Danny MacAskill - \"Way Back Home\"",
    "author_name": "Dave Sowerby",
    "author_url": "http://vimeo.com/tdave",
    "is_plus": "1",
    "html": "<iframe src=\"http://player.vimeo.com/video/17892962\" …",
    "width": 1280,
    "height": 720,
    "duration": 462,
    "description": "A journey from Edinburgh to Skye where Danny finds …",
    "thumbnail_url": "http://b.vimeocdn.com/ts/399/121/399121670_1280.jpg",
    "thumbnail_width": 1280,
    "thumbnail_height": 720,
    "video_id": 17892962
}

For full information, see their oEmbed documentation.

http://(player\.)?vimeo\.com(/video)?/(\d+) covers both of your examples, though I'm sure it could be optimised given further URLs.

This should work: vimeo\.com/(\w*/)*(\d+). The (\w/)* lets you have a URL like vimeo.com/video/something/something-more/more-more-more/XXXXXXXXX without any problems. Then you can grab the XXXXXXXX by just getting the second ground (the \d+). If you know how many digits the video id has you can replace \d+ with \d{n} where n is the number of digits.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!