Skip to content

Getting the YouTube ID with PHP?

Last updated on July 7, 2017

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() :
0 0 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments