Tôi đang cố gắng lấy id từ URL vimeo. Có một cách đơn giản hơn này? Tất cả các url phim vimeo tôi thấy luôn:Cách dễ dàng để lấy id Vimeo từ url vimeo
// VIMEO
$vimeo = $_POST['vimeo'];
function getVimeoInfo($vimeo)
{
$url = parse_url($vimeo);
if($url['host'] !== 'vimeo.com' &&
$url['host'] !== 'www.vimeo.com')
return false;
if (preg_match('~^http://(?:www\.)?vimeo\.com/(?:clip:)?(\d+)~', $vimeo, $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['id'];
}
$vimeo_id = getVimeoInfo($vimeo);
Lưu ý: Câu trả lời này không còn giá trị, và không bao gồm vấn đề bổ sung kết hợp với chế độ riêng tư "chưa niêm yết". Vui lòng xem http://stackoverflow.com/a/34027757/1886079 để có giải pháp chứng minh toàn diện, trong tương lai. – Dashron