これらの両方の一致をチェックする正規表現をどのように記述すればよいでしょうか?
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 に答える