PHP YouTube Embed Function

Here is an update of previous function.
YouTube introduced new iframe embed format so should I a new function

function youtube($id, $type = "standard", $w = 600, $h = 385){
    switch($type){
    case "standard":
    return('<object width="'.$w.'" height="'.$h.'"><param name="movie" value="http://www.youtube.com/v/'.$id.'?fs=1&amp;hl=en_US&amp;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'.$id.'?fs=1&amp;hl=en_US&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'.$w.'" height="'.$h.'"></embed></object>');
    break;

    case "valid":
    return('<object type="application/x-shockwave-flash" data="http://www.youtube.com/v/'.$id.'?fs=1&amp;hl=en_US&amp;rel=0" width="'.$w.'px" height="'.$h.'px">
      <param name="movie" value="http://www.youtube.com/v/'.$id.'?fs=1&amp;hl=en_US&amp;rel=0" />
      <param name="quality" value="high" />
      <param name="wmode" value="transparent" />
      <param name="align" value="TC" />
      <param name="scale" value="exactfit" />
    </object>');
    break;
    
    case "iframe":
    return('<iframe class="youtube-player" type="text/html" width="'.$w.'" height="'.$h.'" src="http://www.youtube.com/embed/'.$id.'"></iframe>');
    break;
    }
}


Usage is simple (as always)...

echo youtube("tRB14mmhh6U", "standard"); //standard w3c invalid embed
echo youtube("tRB14mmhh6U", "valid"); //w3c valid embed
echo youtube("tRB14mmhh6U", "iframe"); //new iframe embed code

By default embed type is standard, you can also set width and height of movie.

Check out the demo: http://webarto.com/demo/56

Have fun!
©2009-2011 Webarto • web design & development • Tuzla // Sarajevo // Beograd