Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/04/2011, 02:38
SeaPirates
 
Fecha de Ingreso: enero-2009
Ubicación: España
Mensajes: 786
Antigüedad: 15 años, 3 meses
Puntos: 9
Recojer información de páginas

Hola, estoy intentando que al introducir la página en un formulario, muestre la infromación de la pagina: Titulo,keywords y descripción.

Esto es lo que he conseguido:

Código:
<?
function substring_between($haystack,$start,$end) { 
    if (strpos($haystack,$start) === false || strpos($haystack,$end) === false) { 
        return false; 
    } else { 
        $start_position = strpos($haystack,$start)+strlen($start); 
        $end_position = strpos($haystack,$end); 
        return substr($haystack,$start_position,$end_position-$start_position); 
    } 
} 

$pagina = file_get_contents("http://".$_POST['pagina']."/");
$text = htmlspecialchars($pagina); 
$titulo = substring_between($text,'&lt;title&gt;','&lt;/title&gt;'); 
$keywords = substring_between($text,'&lt;meta name=&quot;keywords&quot; content=&quot;','"&quot; /&gt;'); 
$descripcion = substring_between($text,'&lt;meta name=&quot;description&quot; content=&quot;','&quot; /&gt;'); 
echo $titulo;
echo $keywords;
echo $descripcion;
?>
<form method="post" action="">
<input type="text" name="pagina">
<input type="submit">
</form>

El problema es que al sacar el contenido entre el meta y " /> coje el último " /> de la pagina y muestra todo el contenido, que puedo hacer?

Última edición por SeaPirates; 26/04/2011 a las 03:41