videourl = $video; $video = explode("=", $video); $video = $video[1]; $video = explode("&", $video); $video = $video[0]; $video = str_replace("?v=", null, $video); $this->videoid = $video; } public function isvalidurl($url) { $analisa = @parse_url($url); $querystr = array(); @parse_str($analisa['query'], $querystr); return @(($analisa['host']=='youtube.com' || $analisa['host']=='www.youtube.com' || $analisa['host']=='m.youtube.com') && $analisa['path'] = '/watch' && isset($querystr['v'])); } function setvideosize($largura, $altura) { $this->largura = (int)$largura; $this->altura = (int)$altura; } function getembedcode() { return ''; } function getvideotitle() { $video = get_meta_tags($this->videourl); return $video['title']; } function getvideotext() { $video = get_meta_tags($this->videourl); return $video['description']; } function getvideoimage() { return 'http://i3.ytimg.com/vi/'.$this->videoid.'/default.jpg'; } } // Exemplo de uso: echo youtube::isvalidurl("http://facebook.com") ? "Sim" : "Nao"; // Nao echo youtube::isvalidurl('https://www.youtube.com/watch?v=rlSW5HTmGhg') ? "Sim" : "Nao"; // Sim $youtube = new youtube('https://www.youtube.com/watch?v=rlSW5HTmGhg'); $youtube->setvideosize(640, 480); echo $youtube->getvideotitle(); echo $youtube->getvideotext(); echo $youtube->getvideoimage(); echo $youtube->getembedcode();