4

If I were using youtube for an example, $link = "http://www.youtube.com/watch?v=hYVVCRqTz1Q"

In the source code of http://www.youtube.com/watch?v=hYVVCRqTz1Q we can find

    <meta property="og:image" content="http://i1.ytimg.com/vi/hYVVCRqTz1Q/hqdefault.jpg?feature=og">

I would like php to use $link to obtain $thumbnail where

$thumbnail = "http://i1.ytimg.com/vi/hYVVCRqTz1Q/hqdefault.jpg"
3

1 Answer 1

0

$link = 'http://www.youtube.com/watch?v=hYVVCRqTz1Q';

Now match if the URL is a valid Youtube Link by matching it with Pattern.

$ypattern= "#(http://www.youtube.com)?/(v/([-|~_0-9A-Za-z]+)|watch\?v\=([-|~_0-9A-Za-z]+)&?.*?)#";
if(preg_match_all($ypattern,$link, $output))
{ 
    foreach ($output[4] AS $video_id)
    {

Youtube Headers

$headers = get_headers('http://gdata.youtube.com/feeds/api/videos/' . $video_id)`;

     if (strpos($headers[0], '200'))
     {
    $youtube = simplexml_load_file('http://gdata.youtube.com/feeds/api/videos/'.$video_id.'?v=1');
            $json = json_decode(file_get_contents('http://gdata.youtube.com/feeds/api/videos/'.$video_id.'?v=2&alt=jsonc'));

Thumbnail >

$thumbnail = $json->data->thumbnail->sqDefault;
                }
            }
        }
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.