Ver Mensaje Individual
  #3 (permalink)  
Antiguo 02/04/2011, 09:57
Avatar de almagropaco_
almagropaco_
 
Fecha de Ingreso: marzo-2008
Ubicación: Mar del Plata
Mensajes: 854
Antigüedad: 17 años
Puntos: 25
Respuesta: Obtener el id de un vídeo de youtube.

Varias soluciones que encontre buscando:
Código PHP:
Ver original
  1. <?
  2. function youtubeUrlToHTML($url, $width = 425, $height = 344) {
  3. parse_str( parse_url( $url, PHP_URL_QUERY ) );
  4. $key = !empty( $v ) ? $v : $url;
  5.  
  6. return '<object width="'.$width.'" height="'.$height.'"><param name="movie" value="http://www.youtube.com/v/'.$key.'&hl=es&fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/'.$key.'&hl=es&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="'.$width.'" height="'.$height.'"></embed></object>';
  7. }
  8. echo youtubeUrlToHTML($_POST['url']);
  9. ?>
Código PHP:
Ver original
  1. function extraer_yt_id($url) {
  2. if (strpos($url,0,5)=='http://' and strlen($url)==42 {
  3. $id=strpos($id, strlen($url)-11, strlen($url));
  4. print 'ID del video: '.$id;
  5. } else {
  6. print 'Enlace inválido';
  7. }
  8. }
Código PHP:
Ver original
  1. // EJEMPLO DE UNA URL
  2. $url="http://www.youtube.com/watch?v=Aw-WHGNsTuQ&feature=related";
  3.  
  4.  
  5. $exp="/v\/?=?([0-9A-Za-z-_]{11})/is";
  6. preg_match_all( $exp , $url , $matches );
  7. $id = $matches[1][0];
  8. echo (empty($id))? "URL NO VALIDA" : $id;

Suerte, y antes de preguntar busca un poquito mas :P