Archive for juny, 2009

Extract youtube id from url

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

9 juny, 2009 at 07:21 1 comentari


Entrades recents

Categories

Tweets


Follow

Get every new post delivered to your Inbox.