Full Stack LAMP - MEAN Developer, Python developer. Certified Azure Developer. Freelance programmer/consultant/trainer.

Getting the YouTube ID with PHP?

Today post is about retrieving Youtube ID from its URL. The below PHP code will allow you to extract the ID number from the given youtube URL.

function to get the Youtube ID

 * get_video_id()
 * @param mixed $url
 * @return string
function get_video_id($url)
    if (!empty($url)) {
        parse_str(parse_url($url, PHP_URL_QUERY), $result);
        return $result['v'];
    } else {
        return FALSE;
//function reference
// parse_url() :
//parse_str() :

Leave a Reply