我将如何编写一个正则表达式来检查这两个匹配项?
问问题
2828 次
3 回答
2
此正则表达式适用于两者(经过测试):
preg_match('#http://(\w+.)?vimeo.com/(video/|moogaloop\.swf\?clip_id=)\w+#i', $content);
更新
要捕获clip_id
使用此调整后的正则表达式:
preg_match('#http://(?:\w+.)?vimeo.com/(?:video/|moogaloop\.swf\?clip_id=)(\w+)#i', $content, $match);
$match[1]
包含剪辑 ID
基本上在每个 '()' 中添加 '?:' 告诉它不要显示在 $match 数组中。
于 2011-03-15T19:40:53.467 回答
1
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;
}
于 2012-02-01T10:06:19.017 回答
0
未经测试但应该可以工作:
preg_match( '/http:\/\/(?:player\.)?vimeo\.com\/(?:moogaloop\.swf\?clip_id=|video\/)/',$string)
$string
你要匹配的东西在哪里。
于 2011-03-15T19:40:41.950 回答