Your Ad Here

Home » PHP Code »

5

The following code is to grabbing the thumbnail image from youtube.

<?
/**
* Function: youtube thumb grabber
*
* @description :
* @param $ : video code, url type (embed/url),size (small/Large),thumb link
* @return : thumb path
*/
if (! function_exists(‘youtube_thumb_grabber’ ))
{

function youtube_thumb_grabber($video_code, $link_type = “embed”, $size = “small”, $thumb_link = “”)
{
if ($video_code != ”)
{
if ($link_type == “embed”)
{

$splited_data = explode(“=”,$video_code);

$video_unique_code = substr(strrchr($splited_data[4],”/”),1,-strlen(strrchr($splited_data[4],”&”)));

}
else if ($link_type == “url”)
{
$splited_data = explode(“=”,$video_code);
$video_unique_code = substr($splited_data[1],0,-strlen(strrchr($splited_data[1],”&”)));
}
else
{
return;
}

if($size == “small”)
{
return “<a href=\”$thumb_link\”><img src=\”http://img.youtube.com/vi/$video_unique_code/2.jpg\” alt=\”No image\” /></a>”;
}
else if ($size == “large”)
{
return “<a href=\”$thumb_link\”><img src=\”http://img.youtube.com/vi/$video_unique_code/0.jpg\” alt=\”No image\” /></a>”;
}
else
{
return “<a href=\”$thumb_link\”><img src=\”http://img.youtube.com/vi/$video_unique_code/2.jpg\” alt=\”No image\” /></a>”;

}

}

}
}

$video_title_url=”http://www.youtube.com/watch?v=ed3Vd39USYQ”;
$video_code=”<object width=\”560\” height=\”340\”><param name=\”movie\” value=\”http://www.youtube.com/v/ed3Vd39USYQ&hl=en_US&fs=1&\”></param><param name=\”allowFullScreen\” value=\”true\”></param><param name=”allowscriptaccess” value=”always”></param><embed src=”http://www.youtube.com/v/ed3Vd39USYQ&hl=en_US&fs=1&” type=\”application/x-shockwave-flash\” allowscriptaccess=\”always\” allowfullscreen=\”true\” width=\”560\” height=\”340\”></embed></object>”;

echo youtube_thumb_grabber($video_code,”embed”,”large”,$video_title_url);
?>

Hope that this will be useful.


You may like these posts

    How to send external html content mail using php?How to manage random header image in joomlaAuto post into Blogspot using php code?How to send mail using phpmailer class

 

5 Comments

  1. anbazhagan says:

    HI

    super working fine after some modification

  2. igaten says:

    nice code… thanks

  3. kuldeep says:

    nice trick but not professional

  4. John says:

    Nice information ; thank you for sharing . . .

Leave a Reply