Home » Php » php – How do I get the Video Id from the URL? (Vimeo)

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

Posted by: admin July 12, 2020 Leave a comment

Questions:

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.

How to&Answers:

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)

Answer:

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