Created
November 13, 2011 15:23
-
-
Save sabarasaba/1362220 to your computer and use it in GitHub Desktop.
Get first url video that matches with the given text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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