user2491321
user2491321

Reputation: 673

php get youtube title and display it

I have created a php script in order to get youtube video image. My code works fine. The only problem is that I cannot get youtube video title and display it near image. Any idea how to do this?

<?php

$find_youtube = "http://www.youtube.com";


if(preg_match("[$find_youtube]", $row['comment'])){

  parse_str( parse_url( $row['comment'], PHP_URL_QUERY ), $my_array_of_vars );

  $row['comment'] = preg_replace("/\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i", "</br><table border='0'><td><img src='http://img.youtube.com/vi/$1/default.jpg' title='YouTube Video' alt='YouTube Video'/></td><td width='250px;' bgcolor='#FDF5E6'>VIDEO TITLE GOES HERE</td></table>", $row['comment']);


}                       

?>

Upvotes: 0

Views: 717

Answers (1)

anu g prem
anu g prem

Reputation: 560

https://dl.google.com/googleio/2010/googleapis-how-google-builds-apis.pdf

<?php
$id = 'VIDEOID';
$xmlData = simplexml_load_string(file_get_contents("http://gdata.youtube.com/feeds/api/videos/{$id}?fields=title"));

$title = (string)$xmlData->title;

echo $title;
?>

Upvotes: 1

Related Questions