Extract youtube id from url

9 juny, 2009 at 07:21 1 comentari

Simple tip in PHP:

function youtubeid($url) {
        $url_parsed = parse_url($url);
	parse_str($url_parsed['query'],$params);
	return $params['v'];
}

So if $url is “http://www.youtube.com/watch?v=pw2-QCXVN2s&feature=popular“, this function will return pw2-QCXVN2s, the id of video.

You can use this id to embed a Youtube video, or paint a video thumbnail: http://img.youtube.com/vi/$id/2.jpg

Entry filed under: desenvolupament. Tags: , , , , , , .

Facebook obre el seu STREAM. Imagina, crea, suma!

1 comentari Add your own

  • 1. ed  |  24 juny, 2009 a les 02:11

    I’ve been trying to show the thumb from a youtube video in my front page for at least 4 hours and not working. Where do you put the
    function youtubeid($url) {
    $url_parsed = parse_url($url);
    parse_str($url_parsed['query'],$params);
    return $params['v'];
    }

    code in wordpress?

    I’m not a coder that’s for sure.

    Thanks for help

    Ed

Deixa un comentari

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Canvia )

Twitter picture

You are commenting using your Twitter account. Log Out / Canvia )

Facebook photo

You are commenting using your Facebook account. Log Out / Canvia )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Entrades recents

Categories

Tweets


Follow

Get every new post delivered to your Inbox.