使用正则表达式preg_match获取ID视频vimeo [英] get id video vimeo with regexp preg_match

查看:240
本文介绍了使用正则表达式preg_match获取ID视频vimeo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从vimeo的网址中获取id视频,但是在源代码中查找有时会是这样的:

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

和其他类似的东西:

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

我只是获得了id视频,但是它必须与regExp一起使用,因为我必须从博客中解析内容,并且在插入代码html时必须像facebook页面一样格式化.

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.

这是我制作的regExp:

This is the regExp that I made:

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

你能帮我吗?感谢您的帮助.

Can you help me? I appreciate all your help.

PD:对不起,我的英语

PD: Sorry for my english

推荐答案

为什么不向Vimeo询问视频?

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

上面的URL将为您提供一个不错的JSON响应,其中包含许多有用的信息,包括视频ID和用于将视频嵌入页面的适当HTML.只需将您的URL传递到如上所述的oEmbed端点即可.

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.

示例JSON响应(用于显示目的的长行被截断)

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
}

有关完整信息,请参见其 oEmbed文档 .

For full information, see their oEmbed documentation.

这篇关于使用正则表达式preg_match获取ID视频vimeo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆