cialis online pharmacy generic xenical cheap cialis online cialis generic viagra online in canada buy cheap levitra online cialis without a perscription order viagra uk no prescription flagyl cheap generic levitra buying viagra in the uk cheap viagra approved cialis deltasone online buy viagra online without prescription non prescription cialis buy orlistat uk buy cialis in india prednisone 60 mg female viagra online buy viagra without prescription celebrex prescriptions buy cialis canada best prices viagra alternative to prednisone cheapest generic levitra levitra 5mg cheap viagra cialis on line buy xenical without prescription online accutane canadian health care prednisone no prescreption viagra online generic female viagra europe buy cialis low price cheap india viagra

Parse YouTube URLs With PHP

Here’s a nice PHP snippet that some of you might find useful with regards to information on YouTube videos. It’s a code that I came across over at PHPZAG that will parse the various types of YouTube URLs and then returning their embed iframe.

<?php
function parseYoutubeURL($link, $width=430, $height=230){
$final = ‘<iframe width=”‘.$width.‘” height=”‘.$height.‘” src=”http://www.youtube.com/embed/{code}” frameborder=”0?></iframe>’;
//se o link for o embed (altera o width e height)
if(stristr($link, “iframe”)){
$link = preg_replace(“/width=(\”)[0-9]+(\”)/”, ‘width=”‘.$width.‘”‘, $link);
$link = preg_replace(“/height=(\”)[0-9]+(\”)/”, ‘height=”‘.$height.‘”‘, $link);
return $link;
}
$parsed = parse_url($link);
//link URL
if(stristr($parsed['path'], ‘watch’) !== false){
parse_str($parsed['query'], $args);
$code = $args['v'];
}//link do embbed
elseif(stristr($parsed['path'], ‘embed’) !== false){
$code = str_replace(“/embed/”, “”, $parsed['path']);
}//short link
elseif($parsed['host'] == ‘youtu.be’){
$code = str_replace(“/”, “”, $parsed['path']);
}
if($code){
$final = str_replace(“{code}”, $code, $final);
return $final;
}else{
return null;
}
}
 ?>

The above code comes with optional width and height.

Related Posts

Adding Instagram Badges to Your WordPress Profile

How to Create a Custom WordPress Registration Form with Flat UI

How to Create A Basic Hipster-Style Layout

How to Style Nav Links Using Floats With HTML5 and CSS3

1 Comment

  1. Moko

    07.21.2012

    Have you ever thought about including a little bit more than just your articles?

    I mean, what you say is valuable and all. Nevertheless just imagine if
    you added some great graphics or video clips to give your posts more, “pop”! Your content is excellent but with images and videos, this blog could certainly be one of the very best in its field. Amazing blog!