Advertisement
Guest User

Get Facebook video ID

a guest
Jul 16th, 2015
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.62 KB | None | 0 0
  1. // Temp store the exploded URL
  2. $tmp = explode('/', $url);
  3.  
  4. // Get the end of the array and go back two
  5. $videos = strtolower($tmp[count($tmp) - 2]);
  6.  
  7. // Check if the URL is /username/videos/
  8. if ($videos == 'videos') {
  9.     // Then the ID is located back one
  10.     $id = $tmp[count($tmp) - 1];
  11.  
  12.     return $id;
  13.    
  14. }else {
  15.     // They used the ?v=id URL
  16.     parse_str(parse_url($url)['query'], $query);
  17.  
  18.     // Check if it's empty or not
  19.     if (!empty($query['v'])) {
  20.         // The ID is within the ?v=
  21.         $id = $query['v'];
  22.     } else {
  23.         // Oh crap shoot, it's neither!
  24.         var_dump($tmp);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement