YouTube video ID from URL

/ Published in: PHP
Save to your folder(s)

Parses any kind of YouTube URL and returns the video ID.

Copy this code and paste it in your HTML
  1. function getYoutubeVideoID($sVideoURL) {
  2. $sVideoID = preg_replace('%.*(v=|/v/)(.+?)(/|&|\\?).*%', '$2', $sVideoURL);
  3. return $sVideoID;
  4. }

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.