Not so complicated, there are only two types of formats that you described.
So, if he has a โvideo,โ then just grab the last digits, but if thatโs how? v, grab v from the url.
<?php
$urls = ['https://www.facebook.com/username2/videos/100000000000000',
'http://www.facebook.com/photo.php?v=107084586333124',
'http://www.facebook.com/photo.php?more=diffictult&v=107084586333124',
'http://www.facebook.com/?v=107084586333124'];
$ids = [];
foreach ($urls as $url) {
$tmp = explode('/', $url);
if (strtolower($tmp[count($tmp) - 2] == 'videos')) {
$ids[$url] = $tmp[count($tmp) - 1];
continue;
}
parse_str(parse_url($url)['query'], $query);
if (!empty($query['v']))
$ids[$url] = $query['v'];
}
print_r($ids);
Output :
Array
(
[https:
[http:
[http:
[http:
:
function getID($url) {
$tmp = explode('/', $url);
if (strtolower($tmp[count($tmp) - 2] == 'videos'))
return $tmp[count($tmp) - 1];
parse_str(parse_url($url)['query'], $query);
if (!empty($query['v']))
return $query['v'];
return false;
}