Jump to content


Photo

Sistema De Noticias Rss


  • Faça o login para participar
2 replies to this topic

#1 franklinho

franklinho

    Normal

  • Usuários
  • 97 posts
  • Sexo:Não informado

Posted 01/04/2007, 14:17

Gente tou usando um codigo aqui pra pegar as noticias da Folha de SP automaticamente, so que nao gostei de uma coisa.
Ficam muitas noticias em uma paginação apenas, varias mesmo ai fica aquela barra de rolagem enorme

Gostaria de saber se tem algum jeito de mostra apenas as 5 primeiras noticias

vou postar o codigo a baixo


<?
$url_fontes=array("http://www1.folha.uo...r/folha/mundo/",
"http://www1.folha.uo...lha/cotidiano/",
"http://www1.folha.uo...lha/ilustrada/",
"http://www1.folha.uo...folha/ciencia/",
"http://www1.folha.uo...olha/educacao/");

// O codigo acima gera uma array da seguinte forma
// $url_fonte[0] ==> http://www1.folha.uo...r/folha/brasil/
// $url_fonte[0] ==> http://www1.folha.uo...br/folha/mundo/
// $url_fonte[1] ==> http://www1.folha.uo...folha/dinheiro/
// $url_fonte[2] ==> http://www1.folha.uo...olha/cotidiano/
// $url_fonte[3] ==> http://www1.folha.uo.../folha/esporte/
// $url_fonte[4] ==> http://www1.folha.uo...olha/ilustrada/
// $url_fonte[5] ==> http://www1.folha.uo...ha/informatica/
// $url_fonte[6] ==> http://www1.folha.uo.../folha/ciencia/
// $url_fonte[7] ==> http://www1.folha.uo...folha/educacao/

if(!isset($ler)){

if(!isset($pg) or $pg==0){
$pagina="index.shtml";
}else{
$pagina="noticias-".$pg.".shtml";
}

if(!isset($secao)){
$secao=0;
}

$array_fonte=file($url_fontes[$secao].$pagina);
while(list($ind, $value)=each($array_fonte)){
$conteudo.=$value;
}

$conteudo=substr($conteudo,strpos($conteudo,"<!--NOTICIAS-->")+strlen("<!--NOTICIAS-->"),strlen($conteudo));

$conteudo=substr($conteudo,"0",strpos($conteudo,"<!--/NOTICIAS-->"));

for($i=1;$i<=6;$i++){
$conteudo=str_replace("noticias-".$i.".shtml",$SCRIPT_NAME."?secao=".$secao."&pg=".$i,$conteudo);
}

$conteudo=str_replace("http://www1.folha.uol.com.br/folha/",$SCRIPT_NAME."?ler="."http://www1.folha.uol.com.br/folha/",$conteudo);

}else{ //if(!isset($ler)){

$array_fonte=file($ler);
while(list($ind, $value)=each($array_fonte)){
$conteudo.=$value;
}

$conteudo=str_replace("<!--TITULO-->","<!--TITULO--><h1>",$conteudo);
$conteudo=str_replace("<a href=","<a target=_blank href=",$conteudo);
$conteudo=str_replace("<A href=","<a target=_blank href=",$conteudo);
$conteudo=str_replace("<A HREF=","<a target=_blank href=",$conteudo);
$conteudo=substr($conteudo,strpos($conteudo,"<!--TITULO-->")+strlen("<!--TITULO-->"),strlen($conteudo));
$conteudo=substr($conteudo,"0",strpos($conteudo,"<!--/TEXTO-->"));

unset($ler);
} //if(!isset($ler)){
?>
<HTML>
<HEAD>
<TITLE>.:: Folha de Notícias ::.</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</HEAD>
<BODY>

<table align="center" width="100%">
<tr>
<td align="center"><a href="http://<?echo $HTTP_HOST.$SCRIPT_NAME;?>?secao=0">Brasil</a></td>
<td align="center"><a href="http://<?echo $HTTP_HOST.$SCRIPT_NAME;?>?secao=1">Mundo</a></td>
<td align="center"><a href="http://<?echo $HTTP_HOST.$SCRIPT_NAME;?>?secao=2">Dinheiro</a></td>
<td align="center"><a href="http://<?echo $HTTP_HOST.$SCRIPT_NAME;?>?secao=3">Cotidiano</a></td>
<td align="center"><a href="http://<?echo $HTTP_HOST.$SCRIPT_NAME;?>?secao=4">Esportes</a></td>
<td align="center"><a href="http://<?echo $HTTP_HOST.$SCRIPT_NAME;?>?secao=5">Ilustrada</a></td>
<td align="center"><a href="http://<?echo $HTTP_HOST.$SCRIPT_NAME;?>?secao=6">Informática</a></td>
<td align="center"><a href="http://<?echo $HTTP_HOST.$SCRIPT_NAME;?>?secao=7">Ciência</a></td>
<td align="center"><a href="http://<?echo $HTTP_HOST.$SCRIPT_NAME;?>?secao=8">Educação</a></td>
</tr>
</table>

<!-- INICIO -->
<?
echo $conteudo;
?>
<!-- FINAL -->
</BODY>
</HTML>



aguardo respostas

um abraço

vlw

#2 Gardenal

Gardenal

    Turista

  • Usuários
  • 30 posts
  • Sexo:Não informado

Posted 01/04/2007, 15:28

Tem um sistema que postaram no forum, eu eu achei..

<?

$filename  = "noticias.xml";
$time	  = 60; // tempo em segundos que vai permitir escrever o arquivo noticias.xml

if (file_exists($filename)) {
	$last_save = filemtime($filename);
} else {
	$last_save = 0;
}

if (($last_save > time() - $time) and (filesize ($filename) > 5) ){
	$fd = fopen ($filename, "r");
	$rss= fread ($fd, filesize ($filename));
	fclose($fd);
} else {
	$matches = array(); 
	$rss	 = join("",file("http://br.noticias.yahoo.com/rss/mundo")); // Faz download do arquivo RSS
	$fp = fopen($filename,"w"); // grava o conteudo no arquivo
	fwrite($fp,$rss);
	fclose($fp);	
}
	
$eng	 ="/<title>(.*?)<\/title>\n(.*?)<link>(.*?)<\/link>/"; // Expressão regular que buscas as informações no arquivo RSS
preg_match_all($eng,$rss,$matches);

//for($i = 1; $i < sizeof($matches[0]); $i++ ) {
for($i = 1; $i < 5; $i++ ) {
	// Imprime o título da notícia com link para a notícia 

	$matches[3][$i] = str_replace("<![CDATA[","",$matches[3][$i]);	 
	$matches[3][$i] = str_replace("]]>","",$matches[3][$i]);
	$matches[1][$i] = str_replace("<![CDATA[","",$matches[1][$i]);	 
	$matches[1][$i] = str_replace("]]>","",$matches[1][$i]);
	echo "- <a class='lnk_black' href=\"".$matches[3][$i]."\" target='_blank'>".$matches[1][$i]."</a><br />";
}
?>
Muito interessante, pega o conteudo do RSS grava em um XML e depois em PHP imprimi..
Detalhe que ele grava só as 5 ultimas notícias no xml..
if (($last_save > time() - $time) and (filesize ($filename) > 5) ){
Basta alterar o valor pra quantas notícias vc desejar capturar.

Edição feita por: Gardenal, 01/04/2007, 15:29.


#3 franklinho

franklinho

    Normal

  • Usuários
  • 97 posts
  • Sexo:Não informado

Posted 01/04/2007, 15:58

Mais eh possivel adptar esse codigo que eu postei mais acima para mostra apenas as 5 ultimas ???/




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq