Search code examples
phpregexpreg-match

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


Example:

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

How do I get x4xvnz?


Solution

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

    $id = strtok(basename($url), '_');