从 vimeo url 获取 Vimeo id 的简单方法 [英] Easy way to get Vimeo id from a vimeo url

查看:51
本文介绍了从 vimeo url 获取 Vimeo id 的简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 vimeo URL 中获取 id.有比这更简单的方法吗?我看到的所有 vimeo 视频网址总是:

I'm trying to get just the id from a vimeo URL. Is there a simpler way than this? All the vimeo video urls I see are always:

https://vimeo.com/29474908

https://vimeo.com/38648446

// 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);

推荐答案

我认为使用 parse_url() 是最好的选择:

I think using parse_url() is the best option:

$vimeo = 'https://vimeo.com/29474908';

echo (int) substr(parse_url($vimeo, PHP_URL_PATH), 1);

这篇关于从 vimeo url 获取 Vimeo id 的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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