Skip to content

Instantly share code, notes, and snippets.

@sabarasaba
Created November 13, 2011 15:23
Show Gist options
  • Save sabarasaba/1362220 to your computer and use it in GitHub Desktop.
Save sabarasaba/1362220 to your computer and use it in GitHub Desktop.
Get first url video that matches with the given text
<?php
function getYoutubeLink($title)
{
@$videoName = ereg_replace('[[:space:]]+', ' ', trim($videoName));
$videoName = urlencode($videoName);
// generate feed URL
$feedURL = "http://gdata.youtube.com/feeds/api/videos?vq={$videoName}";
// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);
if (ISSET($sxml->entry[0]))
{
$media = $sxml->entry[0]->children('http://search.yahoo.com/mrss/');
$attrs = $media->group->player->attributes();
return $attrs['url'];
}
return null;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment