Extract youtube id from url

9 juny, 2009

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. Etiquetes: , , , , , , .

1 Comment Add your own

  • 1. ed  |  24 juny, 2009 at 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

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Categories

Entrades recents

Blogroll

Arxius

Etiquetes

accés remot ajax benvinguda cakephp chiquilicuatre comunicació concurs crossloop estrelles eurovisión Eyesores eyesoreworld Facebbok Garage Barcelona Facebook Facebook Open Plataform forms fotografia greenbow Grow Together hamachi incidència Intermón Oxfam ipsec jquery jquery.forms linux Omatech openswan perra presentacio Product Pulse projectes psk roadwarrior rodolfo rodolfo chiquilicuatre Sant Julià de Ramis Sclipo sistemes suport telecobàsquet uploads vhost vnc zyxell vpn client