Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
915 views
in Technique[技术] by (71.8m points)

php - get id video vimeo with regexp preg_match

I try to get the id video from an url of vimeo, but looking in the source code sometimes it comes like:

http://vimeo.com/XXXXXXXXX

and others like:

http://player.vimeo.com/video/XXXXXXXXX

I just get the id video, but it must be with regExp because I must parse a content from a blog and format like a facebook page does when we insert code html.

This is the regExp that I made:

/vimeo.com/(w+s*/?)*([0-9]+)*$/i

Can you help me? I appreciate all your help.

PD: Sorry for my english

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...