Tuesday, August 28, 2012

you tube url parsing uisng php

/*
step-1 create class YoutubeParserbybikash.php and include your page this class file and create obeject  and pass your youtube url


 class YoutubeParserbybikash{
var $source = '';
var $unique = false;
var $suggested = false;
var $https = false;
var $privacy = false;
var $width = 354;
var $height = 234;
function __construct(){
}
function set($key,$val){
return $this->$key = $val;
}
function playyoutube(){
$return = Array();
$domain = 'http'.($this->https?'s':'').'://www.youtube'.($this->privacy?'-nocookie':'').'.com';
$size = 'width="'.$this->width.'" height="'.$this->height.'"';
preg_match_all('/(youtu.be\/|\/watch\?v=|\/embed\/)([a-z0-9\-_]+)/i',$this->source,$matches);
if(isset($matches[2])){
if($this->unique){
$matches[2] = array_values(array_unique($matches[2]));
}
foreach($matches[2] as $key=>$id) {
$return[$key]['id'] = $id;
$return[$key]['embedold'] = '';
}
}
return $return[$key]['embedold'];
}
}
------------------------------end class and create object to access-----------------------------------------
$youtube = new YoutubeParserbybikash;
$youtube->set('source','http://www.youtube.com/watch?v=R55e-uHQna0&feature=topvideos');
echo'
';
print_r($youtube->playyoutube());
echo'
';

No comments:

Post a Comment