我试图从vimeo URL获取id.有比这更简单的方法吗?我看到的所有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);
Run Code Online (Sandbox Code Playgroud) 我在网站上看到了几个不同的例子,但它没有从所有youtube选项中获取id ...例如,以下链接不适用于下面的正则表达式模式.任何帮助都会很精彩.提前致谢:
如果用户访问youtube主页并点击其中一个视频,他们就会给出这个网址:http : //www.youtube.com/watch?v= hLSoU53DXK8&feature=g-vrec
我的正则表达式将它放在数据库中:hLSoU53DXK8-vrec,我需要它没有-vrec.
// YOUTUBE
$youtube = $_POST['youtube'];
function getYoutubeId($youtube) {
$url = parse_url($youtube);
if($url['host'] !== 'youtube.com' &&
$url['host'] !== 'www.youtube.com'&&
$url['host'] !== 'youtu.be'&&
$url['host'] !== 'www.youtu.be')
return false;
$youtube = preg_replace('~
# Match non-linked youtube URL in the wild. (Rev:20111012)
https?:// # Required scheme. Either http or https.
(?:[0-9A-Z-]+\.)? # Optional subdomain.
(?: # Group host alternatives.
youtu\.be/ # Either youtu.be,
| youtube\.com # or youtube.com followed by
\S* # Allow anything up to …Run Code Online (Sandbox Code Playgroud)