Ver Mensaje Individual
  #7 (permalink)  
Antiguo 10/12/2012, 15:38
Javivo
 
Fecha de Ingreso: agosto-2012
Ubicación: Zafra
Mensajes: 25
Antigüedad: 11 años, 8 meses
Puntos: 2
Respuesta: obtener titulo de una url almacenada en mysql

Prueba esta función para sacar el title de un sitio a ver si te sirve.

Código PHP:
Ver original
  1. <?php
  2.  
  3.   $www = "http://www.forosdelweb.com"; //Pon aquí la URL a la que quieras extraer el title
  4.   $html = file_get_contents($www);
  5.  
  6.   $inicio = strpos ($html, '<title>');
  7.   $fin = strpos ($html, '</title>');
  8.  
  9.   $largo = $fin - $inicio - 7;
  10.  
  11.   $titulo = substr ($html, ($inicio+7),$largo);
  12.  
  13.   echo $titulo;
  14.  ?>

La puedes guardar en una función o hacer con ella lo que quieras, eso ya depende de tu finalidad..
El resultado en este caso es: Foros del Web, comunidad para aprender web

Espero que te sirva =)

Tengo algo de tiempo así que te la he puesto a modo de función:

Código PHP:
Ver original
  1. <?php /*AQUI TIENES LA FUNCION*/
  2.  
  3. function title($www){
  4.   $html = file_get_contents($www);
  5.   $inicio = strpos ($html, '<title>');
  6.   $fin = strpos ($html, '</title>');
  7.  
  8.   $largo = $fin - $inicio - 7;
  9.  
  10.   $titulo = substr ($html, ($inicio+7),$largo);
  11.  
  12.   return $titulo;
  13. }
  14.  
  15. /*AQUI EL CÓMO UTILIZARLA*/
  16.  
  17. // si tienes la url almacenada en la base de datos, bastaría con hacer algo así
  18. $sql = mysql_query("SELECT campo FROM tabla where campo = elquesea");
  19. if($reg=mysql_fetch_array($sql)){
  20. $url=$reg["campodelaurldetubasededatos"];
  21.  
  22. title($url);
  23. }
  24. ?>

Solo es un simple ejemplo..

Última edición por Javivo; 10/12/2012 a las 15:58