Php vimeo视频的简单正则表达式

Php vimeo视频的简单正则表达式,php,regex,vimeo,Php,Regex,Vimeo,我该如何编写一个正则表达式来检查这两个函数是否匹配 未经测试,但应能正常工作: preg_match( '/http:\/\/(?:player\.)?vimeo\.com\/(?:moogaloop\.swf\?clip_id=|video\/)/',$string) 其中,$string是您要匹配的任何对象。此正则表达式适用于这两种情况(已测试): 更新 要捕获剪辑id,请使用此调整后的正则表达式: preg_match('#http://(?:\w+.)?vimeo.com/(?:vi

我该如何编写一个正则表达式来检查这两个函数是否匹配


未经测试,但应能正常工作:

preg_match( '/http:\/\/(?:player\.)?vimeo\.com\/(?:moogaloop\.swf\?clip_id=|video\/)/',$string)

其中,
$string
是您要匹配的任何对象。

此正则表达式适用于这两种情况(已测试):

更新

要捕获剪辑id,请使用此调整后的正则表达式:

preg_match('#http://(?:\w+.)?vimeo.com/(?:video/|moogaloop\.swf\?clip_id=)(\w+)#i', $content, $match);
$match[1]
包含剪辑id


基本上,在每个“()”中添加“?:”会告诉它不要显示在$match数组中。

刮擦是邪恶的。收集你自己的内容。写两个表达式如何,每个表达式一个?还有,你写什么了吗?“如果你已经写了一封信的话,更正你的简历就容易多了。”托马拉克——谁说他在刮呢?也许他想写一个检测vimeo链接的CMS?是的,我有这个:%vimeo\.com/(\d{7,9})\b%我知道它只查找vimeo.com/video\u id,虽然是的,我实际上只是在我们网站的博客帖子中搜索一个视频网站地图这一个可行,但匹配如下:Array([0]=>Array([0]=>[1]=>)[1]=>Array([0]=>www.1]=>www.2]=>Array([0]=>moogaloop.swf?clip\u id=[1]=>moogaloop.swf?clip\u id=))我有没有办法捕捉到这个片段的id?我的荣幸。很高兴我能提供帮助。您的正则表达式的更新版本不适用于此URL:(@juanchopx2用于该URL,请尝试:preg_match('#http://(?:\w+)?vimeo.com/(\d+)#I',$content,$match);同样,$match[1]是URL中的您的id。注意,此正则表达式的id必须是数字。
function getVimeoInfo($link)
 {
    if (preg_match('~^http://(?:www\.)?vimeo\.com/(?:clip:)?(\d+)~', $link, $match)) 
    {
        $id = $match[1];
    }
    else
    {
        $id = substr($link,10,strlen($link));
    }

    if (!function_exists('curl_init')) die('CURL is not installed!');
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://vimeo.com/api/v2/video/$id.php");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    $output = unserialize(curl_exec($ch));
    $output = $output[0];
    curl_close($ch);
    return $output;
}
function getVimeoInfo($link)
 {
    if (preg_match('~^http://(?:www\.)?vimeo\.com/(?:clip:)?(\d+)~', $link, $match)) 
    {
        $id = $match[1];
    }
    else
    {
        $id = substr($link,10,strlen($link));
    }

    if (!function_exists('curl_init')) die('CURL is not installed!');
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://vimeo.com/api/v2/video/$id.php");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    $output = unserialize(curl_exec($ch));
    $output = $output[0];
    curl_close($ch);
    return $output;
}