Foros del Web » Programando para Internet » PHP »

Expresion regular videos youtube

Estas en el tema de Expresion regular videos youtube en el foro de PHP en Foros del Web. Hola a todos ¿Sabéis si hay alguna expresion regular por ahí para validar el codigo de los videos de youtube?? ¿Y un script para modificar ...
  #1 (permalink)  
Antiguo 18/11/2009, 06:29
 
Fecha de Ingreso: junio-2003
Mensajes: 778
Antigüedad: 20 años, 10 meses
Puntos: 1
Expresion regular videos youtube

Hola a todos

¿Sabéis si hay alguna expresion regular por ahí para validar el codigo de los videos de youtube??

¿Y un script para modificar el ancho y alto?

Gracias por ayuda por adelantado
  #2 (permalink)  
Antiguo 18/11/2009, 06:32
Colaborador
 
Fecha de Ingreso: octubre-2009
Ubicación: Tokyo - Japan !
Mensajes: 3.867
Antigüedad: 14 años, 6 meses
Puntos: 334
Respuesta: Expresion regular videos youtube

a q te refieres con validar?.. ver si el link existe?
__________________
More about me...
~ @rhyudek1
~ Github
  #3 (permalink)  
Antiguo 18/11/2009, 07:34
 
Fecha de Ingreso: octubre-2004
Ubicación: Uruguay
Mensajes: 386
Antigüedad: 19 años, 6 meses
Puntos: 4
Respuesta: Expresion regular videos youtube

Código:
youtube.class.php
<?php
 
# YouTube PHP class
# used for embedding videos as well as video screenies on web page without single line of HTML code
#
# Dedicated to my beloved brother FILIP. Rest in peace!
#
# by Avram, www.avramovic.info
 
class YouTube {
 
function _GetVideoIdFromUrl($url) {
    $parts = explode('?v=',$url);
    if (count($parts) == 2) {
        $tmp = explode('&',$parts[1]);
        if (count($tmp)>1) {
            return $tmp[0];
        } else {
            return $parts[1];
        }
    } else {
        return $url;
    }
}
 
function EmbedVideo($videoid,$width = 425,$height = 350) {
    $videoid = $this->_GetVideoIdFromUrl($videoid);
    return '<object width="'.$width.'" height="'.$height.'"><param name="movie" value="http://www.youtube.com/v/'.$videoid.'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'.$videoid.'" type="application/x-shockwave-flash" wmode="transparent" width="'.$width.'" height="'.$height.'"></embed></object>';
}
 
function GetImg($videoid,$imgid = 1) {
    $videoid = $this->_GetVideoIdFromUrl($videoid);
    return "http://img.youtube.com/vi/$videoid/$imgid.jpg";
}
 
function ShowImg($videoid,$imgid = 1,$alt = 'Video screenshot') {
    return "<img src='".$this->GetImg($videoid,$imgid)."' width='130' height='97' border='0' alt='".$alt."' title='".$alt."' />";
}
 
}
 
?>

tester.php
Código:
include "youtube.class.php";
$video="http://www.youtube.com/watch?v=dBoMvJM2tIY";
 
 
 
$jutjub = new YouTube();
    $imagen1= $jutjub->GetImg($video,2);
    $ch = curl_init($imagen1);
    if ($ch){
        $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)"; 
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
        curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        $html = htmlentities(curl_exec($ch)); 
        $info= curl_getinfo($ch);  
        curl_close($ch);
        if ($info['content_type'] != "image/jpeg")
              {$error="yes"; }
 
    } else { $error="yes";}
?><? if ($error!="yes") { ?><?=$jutjub->GetImg($video,2);?><?=$jutjub->GetImg($video,2);?>
<?    echo   $jutjub->EmbedVideo($video,550,350);?>
<? } ?>
  #4 (permalink)  
Antiguo 18/11/2009, 09:07
 
Fecha de Ingreso: junio-2003
Mensajes: 778
Antigüedad: 20 años, 10 meses
Puntos: 1
Respuesta: Expresion regular videos youtube

excelente gerazmv¡¡ un 10 en la respuesta
  #5 (permalink)  
Antiguo 18/11/2009, 09:31
 
Fecha de Ingreso: octubre-2004
Ubicación: Uruguay
Mensajes: 386
Antigüedad: 19 años, 6 meses
Puntos: 4
Respuesta: Expresion regular videos youtube

de nada. si se puede se ayuda. XD
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Tema Cerrado




La zona horaria es GMT -6. Ahora son las 20:05.