Skip to content

Instantly share code, notes, and snippets.

@smahi
Forked from james2doyle/youtube-title.php
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smahi/f79b77b69bf55a138bf0 to your computer and use it in GitHub Desktop.
Save smahi/f79b77b69bf55a138bf0 to your computer and use it in GitHub Desktop.
function youtube_title() {
$id = 'YOUTUBE_ID';
// returns a single line of XML that contains the video title. Not a giant request. Use '@' to suppress errors.
$videoTitle = @file_get_contents("http://gdata.youtube.com/feeds/api/videos/{$id}?v=2&fields=title");
// look for that title tag and get the insides
preg_match("/<title>(.+?)<\/title>/is", $videoTitle, $titleOfVideo);
return $titleOfVideo[1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment