Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

Get youtube thumbnail

This function can get thumbnail of youtube video. It takes embed code or link to youtube video as parameter and returns link to thumbnail of that video from youtube server.

<?php
//you can pass embed code or youtube link
function youtube_thumbnail($youtube){
    //checking if anything found using embed code expression
    preg_match('/http://[w.]*youtube.com/v/([^?"]*)/is', 
                $youtube, $match);
    if(!empty($match))
    {
        //if yes returning thumbnail link
        return "http://i2.ytimg.com/vi/".$match[1]."/default.jpg";
    }
    else
    {
        //checking if anything is found using link expression
        preg_match("/http://[w.]*youtube.com/watch?v=([^&]*)/is", 
                    $youtube, $match);
        if(!empty($match))
        {
            //if yes returning thumbnail link
            return "http://i2.ytimg.com/vi/".$match[1]."/default.jpg";
        }
        else
        {
            //else nothing found, returning false
            return false;
        }
    }
}   
//getting thumbnail from youtube embed code
$img = youtube_thumbnail('<object width="480" height="385"><param name="movie" 
value="http://www.youtube.com/v/YqZ3ek6d15E?fs=1&amp;hl=en_US"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always">
</param><embed src="http://www.youtube.com/v/YqZ3ek6d15E?fs=1&amp;hl=en_US" 
type="application/x-shockwave-flash" allowscriptaccess="always" 
allowfullscreen="true" width="480" height="385"></embed></object>');
echo "<p>From embed code: </p><p><img src='".$img."'/></p>";

//getting thumbnail from youtube link
$img = youtube_thumbnail('http://www.youtube.com/watch?v=oTqzAFNwbeo&feature=fvw');
echo "<p>From youtube link: </p><p><img src='".$img."'/></p>";
?>

You may also be interested in:

Powered by BlogAlike.com

blog comments powered by Disqus