user317005
user317005

Reputation:

How do I get the Video Id from the URL? (Vimeo)

PHP

<?php

$url = 'http://vimeo.com/25451551';

/* http://www.vimeo.com/25451551 ... www.vimeo.com/25451551 */

$url = preg_match('???', $url);

echo $url;

?>

Output

25451551

Any help with this would be appreciated. Thanks.

Upvotes: 7

Views: 8717

Answers (2)

Maxim Krizhanovsky
Maxim Krizhanovsky

Reputation: 26699

$url = 'http://vimeo.com/25451551/test';
$result = preg_match('/(\d+)/', $url, $matches);
if ($result) {
    var_dump($matches[0]);
}

Upvotes: 9

user142162
user142162

Reputation:

If video IDs are allowed to start with a 0, you may need to tune the following code a bit:

$url = 'http://vimeo.com/25451551';
sscanf(parse_url($url, PHP_URL_PATH), '/%d', $video_id);
// $video_id = int(25451551)

Upvotes: 16

Related Questions