Return to Snippet

Revision: 33895
at October 14, 2010 22:29 by jhonqwerty


Initial Code
<?php
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;
}

//Usage
$video_id = youtubeid("http://www.youtube.com/watch?v=Fv2aS8YtpmU");

echo $video_id;

?>

Initial URL


Initial Description
Youtube ID simple extractor

Initial Title
Youtube ID extractor

Initial Tags
regex, function

Initial Language
PHP