How to get video id from url? (DailyMotion)

Example:

http://www.dailymotion.com/video/x4xvnz_the-funny-crash-compilation_fun 

How do i get x4xvnz ?

+6
source share
5 answers

You can use basename [docs] to get the last part of the URL, and then strtok [docs] to get the identifier (all characters before the first _ ):

 $id = strtok(basename($url), '_'); 
+7
source
 /video\/([^_]+)/ 

gotta do the trick. This captures in the first capture all the text after video/ to the first _ .

+4
source
 preg_match('#<object[^>]+>.+?http://www.dailymotion.com/swf/video/([A-Za-z0-9]+).+?</object>#s', $dailymotionurl, $matches); // Dailymotion url if(!isset($matches[1])) { preg_match('#http://www.dailymotion.com/video/([A-Za-z0-9]+)#s', $dailymotionurl, $matches); } // Dailymotion iframe if(!isset($matches[1])) { preg_match('#http://www.dailymotion.com/embed/video/([A-Za-z0-9]+)#s', $dailymotionurl, $matches); } $id = $matches[1]; 
+2
source

I use this:

 function getDailyMotionId($url) { if (preg_match('!^.+dailymotion\.com/(video|hub)/([^_]+)[^#]*(#video=([^_&]+))?|(dai\.ly/([^_]+))!', $url, $m)) { if (isset($m[6])) { return $m[6]; } if (isset($m[4])) { return $m[4]; } return $m[2]; } return false; } 

It can handle various URLs:

 $dailymotion = [ 'http://www.dailymotion.com/video/x2jvvep_coup-incroyable-pendant-un-match-de-ping-pong_tv', 'http://www.dailymotion.com/video/x2jvvep_rates-of-exchange-like-a-renegade_music', 'http://www.dailymotion.com/video/x2jvvep', 'http://www.dailymotion.com/hub/x2jvvep_Galatasaray', 'http://www.dailymotion.com/hub/x2jvvep_Galatasaray#video=x2jvvep', 'http://www.dailymotion.com/video/x2jvvep_hakan-yukur-klip_sport', 'http://dai.ly/x2jvvep', ]; 

Check out my github ( https://github.com/lingtalfi/video-ids-and-thumbnails/blob/master/testvideo.php ), I provide functions for getting identifiers (as well as thumbnails) from youtube, vimeo and dailymotion.

+1
source
 <?php $output = parse_url("http://www.dailymotion.com/video/x4xvnz_the-funny-crash-compilation_fun"); // The part you want $url= $output['path']; $parts = explode('/',$url); $parts = explode('_',$parts[2]); echo $parts[0]; 

http://php.net/manual/en/function.parse-url.php

0
source

Source: https://habr.com/ru/post/891596/


All Articles