[youtube]URL[/youtube] |
[eluser]EEssam[/eluser]
Hi, Can anyone tell me please how can I parse the following: Code: [youtube]http://www.youtube.com/v/PC4HhI0bK4c&hl=en&fs=1[/youtube] To: Code: <object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/PC4HhI0bK4c&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/PC4HhI0bK4c&hl=en&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object> Thanks.
[eluser]alectrash[/eluser]
I just get link: http://uk.youtube.com/watch?v=VlBWm_UXbS0 and then get id after 'v' ie VlBWm_UXbS0 i then call this $url and pass to simplepie like so: Code: function add_youtube($url) get fiaz khans simplepie tutorial here http://www.nextbigleap.com/blog/developm...deigniter/ enjoy!
[eluser]Jamie Rumbelow[/eluser]
Do a simple preg_replace()... Code: preg_replace('[youtube](*.)[/youtube]', '<object width="425" height="344"><param name="movie" value="$1"></param><param name="allowFullScreen" value="true"></param><embed src="$1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>');
[eluser]Unknown[/eluser]
<?php // Get Youtube Data Feed With use Of Simple Pie in PHP // Munir Sunni ( [email protected] ) include('simplepie/simplepie.class.php'); $urlList = array(); $urlList = ( //List Of Youtube Videos 'http://www.youtube.com/watch?v=D5xxUkLhZe4', 'http://www.youtube.com/watch?v=VBURsTurlH8', 'http://www.youtube.com/watch?v=_qNx7ggPTLc', //List Of Youtube Channels 'http://www.youtube.com/user/jalil7', 'http://www.youtube.com/user/maddyvora' ); foreach ($urlList as $videoUrl) { // Check that if this Video/channel is actully coming from Youtube or not if (stristr(strtolower($videoUrl), 'youtube.com')) { // Explode all the value through '/' for getting Video/channel ID and stored into array $linkHref = explode('/', $videoUrl); // Get the Five Charactor of third value of array to defing that if it is video or channel $linkHrefText = substr($linkHref[3], 0, 5); if ($linkHrefText == 'watch') { // Get the Video Id of Youtube Video $urlVars = GetYoutubeUrlVars($videoUrl); if ($urlVars['v'] != '') { $videoAndChannelList[] = 'http://gdata.youtube.com/feeds/videos?vq=' . $urlVars['v']; } } else { // Get the Channel Id of Youtube Channel $channelName = ($linkHref[3] != 'user') ? $linkHref[3] : $linkHref[4]; $videoAndChannelList[] = 'http://gdata.youtube.com/feeds/api/users/'. $channelName .'/uploads'; } } } $feed = new SimplePie(); $feed->set_cache_location('SimplePie/cache'); //Put the List of channel/videos from which you get Videos $feed->set_feed_url($videoAndChannelList); $feed->init(); $feed->handle_content_type(); $items = $feed->get_items(); $items = array_slice($items, 0, 50, true); foreach ($items as $item) { $date = $item->get_date('U'); $link = $item->get_permalink(); $enclosure = $item->get_enclosure(); if ($enclosure) { $title = $enclosure->get_title(); $duration = $enclosure->duration; $thumb = $enclosure->get_thumbnail(); $description = $enclosure->get_description(); } if (empty($link)) $link = $item->feed->feed_url; $object = null; $object->Title = $title; $object->Date = $date; $object->Link = $link; $object->Description = $description; $object->Duration = $duration; $object->Thumb = $thumb; $externalVideos[] = $object; } echo '<pre>'; print_r($externalVideos); function GetYoutubeUrlVars($url) { $vars = array(); $urlstr = substr($url, strpos($url, '?') + 1, strlen($url)); $urlargs = explode('&',$urlstr); foreach ($urlargs as $arg) { $exploded = explode('=', $arg); if (count($exploded) > 1) $vars[$exploded[0]] = $exploded[1]; } return $vars; } ?> Quote: |
Welcome Guest, Not a member yet? Register Sign In |