'Fetch YouTube Video Id from youtube URL in zend framework
This is my youtube tube URL which is coming from facebook Id. I have fetch this url using FQL Query in facebook in Zend Framework
This is my url = "http://www.youtube.com/attribution_link?a=AbE6fYtNaa4&u=%2Fwatch%3Fv%3DNbyHNASFi6U%26feature%3Dshare"
Now I need to fetch its ID so that I can pass it to this code so that i can generate its vidoe details.
function listYoutubeVideo($id) {
$video = array();
try {
$yt = new Zend_Gdata_YouTube();
$videoEntry = $yt->getVideoEntry($id);
$videoEntry = $yt->getQueryUrl($id);
$videoThumbnails = $videoEntry->getVideoThumbnails();
$video = array(
'thumbnail' => $videoThumbnails[0]['url'],
'title' => $videoEntry->getVideoTitle(),
'description' => $videoEntry->getVideoDescription(),
'tags' => implode(', ', $videoEntry->getVideoTags()),
'url' => $videoEntry->getVideoWatchPageUrl(),
'flash' => $videoEntry->getFlashPlayerUrl(),
'dura' => $videoEntry->getVideoDuration(),
'id' => $videoEntry->getVideoId()
);
} catch (Exception $e) {
echo $e->getMessage();
exit();
}
return $video;
}
So I just need to find its youtube ID from youtube URL in Zend Framework. Plz provide me solutions. Is there any method exist in "Zend_Gdata_YouTube" class from where i can get its ID form passing its youtube URL
Solution 1:[1]
public function get_id($url)
{
$ytshorturl = 'youtu.be/';
$ytlongurl = 'www.youtube.com/watch?v=';
if (strpos($url, $ytshorturl) !== false) {
$url = str_replace($ytshorturl, $ytlongurl, $url);
}
$components = parse_url($url);
parse_str($components['query'], $results);
return $results['v'];
}
$url = "https://youtu.be/oeg192rQ1xE"; //sample url
print(get_id($url));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lajos Arpad |
