Nunca probe ese método, pero en Favs (Un proyecto medio abandonado que tengo -.-) estoy usando este y funciona perfecto... por ahi le sirve a alguien
Solo lo modifiqué para utilizar file_get_content, originalmente estaba usando cURL.Código PHP:function get_site_name($url)
{
$page = file_get_contents($url);
preg_match('#<title>(.*)</title>#s', $page, $title);
if(!empty($title[1]))
{
return $title[1];
}
else
{
return "No se obtuvo el título";
}
}
« about.me »
Pongo algo así, pero no me funcionaCódigo PHP:<?
global $link_head;
global $link_time;
?>
<html>
<head>
<title>Redirigiendo a <?=$link_head?></title>
<meta http-equiv="refresh" content="<?=$link_time?>; URL=<?=$link_head?>">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<center>
<h1>Cargando la URL...</h1>
<br />
<img src="http://crix.us/loading.gif" />
<p>Por Favor espere <?=$link_time?> segundos mientras es redirigido hacia <strong><a href="<?=$link_head?>"><?=$link_head?></a></strong> Gracias.</p>
<?php
$url = "<?=$link_head?>";
$html = file_get_contents($url);
$ini = strpos ($html, '<title>');
$fin = strpos ($html, '</title>');
$long = $fin - $ini - 7;
$titulo = substr ($html, ($ini+7),$long);
echo $titulo;
// Si no se imprimen correctamente las tildes, quitar el siguiente comentario
// echo utf8_encode($titulo);
?>
<br />
</center>
<div class="clearer"></div>
</div>
</body>
</html>Disculpen mi ignorancia. No sé como hacerlo funcionar, sólo quiero que meustre el titulo de la página para la relevancia en los anuncios. Es solo un fragmento del código, no es todo el código jejeje
Espero que lo haya hecho mal, por que espero que funcione de alguna manera xD Gracias!
Supongo que sera eso, pero... de donde sacas las variables $link_head y $link_time?Código PHP:<?
global $link_head;
global $link_time;
?>
<html>
<head>
<title>Redirigiendo a <?=$link_head?></title>
<meta http-equiv="refresh" content="<?=$link_time?>; URL=<?=$link_head?>">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<center>
<h1>Cargando la URL...</h1>
<br />
<img src="http://crix.us/loading.gif" />
<p>Por Favor espere <?=$link_time?> segundos mientras es redirigido hacia <strong><a href="<?=$link_head?>"><?=$link_head?></a></strong> Gracias.</p>
<?php
$url = $link_head;
$html = file_get_contents($url);
$ini = strpos ($html, '<title>');
$fin = strpos ($html, '</title>');
$long = $fin - $ini - 7;
$titulo = substr ($html, ($ini+7),$long);
echo $titulo;
// Si no se imprimen correctamente las tildes, quitar el siguiente comentario
// echo utf8_encode($titulo);
?>
<br />
</center>
<div class="clearer"></div>
</div>
</body>
</html>
pd: Por si no se nota, edite la linea $url = $link_head;
Es la forma "corta" (Además de no ser oficial y estar deprecada) para imprimir algo en la página (echo). En esa linea no se necesitas imprimir nada, solo "asociar" su contenido a otra variable.Código PHP:<?=$xxx?>
Última edición por Santiago; 13-ago-2009 a las 18:59
« about.me »
Mmm, ni idea amigo =S Pero el hosting es Globat - Affordable Web Hosting
Aqui tienes el script para descargar: http://crix.us/script.zip
No obtienes ningún error?
Prueba con esto, por las dudas:
Código PHP:<?
global $link_head;
global $link_time;
?>
<html>
<head>
<title>Redirigiendo a <?=$link_head?></title>
<meta http-equiv="refresh" content="<?=$link_time?>; URL=<?=$link_head?>">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<center>
<h1>Cargando la URL...</h1>
<br />
<img src="http://crix.us/loading.gif" />
<p>Por Favor espere <?=$link_time?> segundos mientras es redirigido hacia <strong><a href="<?=$link_head?>"><?=$link_head?></a></strong> Gracias.</p>
<?php
$url = $link_head;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $urlstring);
curl_setopt($ch, CURLOPT_REFERER, "http://www.tusitio.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
$titulo = 'No se pudo obtener el título';
if($data)
{
$ini = strpos ($html, '<title>');
$fin = strpos ($html, '</title>');
$long = $fin - $ini - 7;
$titulo = substr ($html, ($ini+7),$long);
}
echo $titulo;
// Si no se imprimen correctamente las tildes, quitar el siguiente comentario
// echo utf8_encode($titulo);
?>
<br />
</center>
<div class="clearer"></div>
</div>
</body>
</html>
« about.me »
Mmm, no bro, no funciona.
Fijate
Gracias por la ayuda![]()
parece que a varios nos llamo la antencion hacer esto.
Yo dejo mi aporte, aunque veo que Kn ya hizo lo que querian.
Lo que yo hice imprime un link + el tituloCódigo PHP:<?
function extraertituloenlaces($web){
$viewsource = file_get_contents($web)or die('FAK!! no existe o algo esta mal');
$iniciotitulo = strpos($viewsource, '<title>') ;
$finaltitulo = strpos($viewsource, '</title>') - $iniciotitulo;
$titulo = substr($viewsource, $iniciotitulo+7, $finaltitulo-7);
echo '<a href='.$web.'>'. $titulo.'</a>' ;
}
extraertituloenlaces('http://www.forobeta.com');
?>
¿Cómo puedo hacer esto con los enlaces? - Página 3
Última edición por danielmd; 13-ago-2009 a las 20:24
Siguemesta...
Twitter: @danielmd
Actualmente hay 1 usuarios leyendo este tema. (0 miembros y 1 invitados)