YouTube ID extractor

Date Submitted Fri. Jul. 20th, 2007 7:42 PM
Revision 1 of 1
Scripter ColdKeyboard
Tags Extract | ID | youtube
Comments 2 comments
Function that you can use to extract the ID from YouTube links that
look like this:

and you can extract this "Fv2aS8YtpmU" so you can use it to get thumbnails that look like :[videoid]/default.jpg

function youtubeid($url) {
        if (preg_match('%youtube\\.com/(.+)%', $url, $match)) {
                $match = $match[1];
                $replace = array("watch?v=", "v/", "vi/");
                $match = str_replace($replace, "", $match);
        return $match;

$video_id = youtubeid("");

echo $video_id;


Sasa Karanovic

Sasa Karanovic


Comments Nice
Thu. Aug. 23rd, 2007 8:42 AM    Newbie navster
  Comments Youtube Video ID only
Mon. Dec. 24th, 2007 7:16 PM    Newbie mmoraes