Foros del Web » Programando para Internet » PHP »

Leer rss con php

Estas en el tema de Leer rss con php en el foro de PHP en Foros del Web. Tengo este codigo php Código PHP: <?php /* Created by Global Syndication's RSS Parser [url]http://www.globalsyndication.com/rss-parser[/url] */ set_time_limit ( 0 ); $file  =  "http://www.lanacion.com.ar/herramientas/rss/index.asp?origen=2" ; $rss_channel  = array(); $currently_writing  =  "" ; ...
  #1 (permalink)  
Antiguo 26/04/2006, 14:06
 
Fecha de Ingreso: marzo-2005
Mensajes: 49
Antigüedad: 19 años, 1 mes
Puntos: 2
Leer rss con php

Tengo este codigo php
Código PHP:
<?php

/*
Created by Global Syndication's RSS Parser
[url]http://www.globalsyndication.com/rss-parser[/url]
*/

set_time_limit(0);

$file "http://www.lanacion.com.ar/herramientas/rss/index.asp?origen=2";

$rss_channel = array();
$currently_writing "";
$main "";
$item_counter 0;

function 
startElement($parser$name$attrs) {
       global 
$rss_channel$currently_writing$main;
       switch(
$name) {
           case 
"RSS":
           case 
"RDF:RDF":
           case 
"ITEMS":
               
$currently_writing "";
               break;
           case 
"CHANNEL":
               
$main "CHANNEL";
               break;
           case 
"IMAGE":
               
$main "IMAGE";
               
$rss_channel["IMAGE"] = array();
               break;
           case 
"ITEM":
               
$main "ITEMS";
               break;
           default:
               
$currently_writing $name;
               break;
       }
}

function 
endElement($parser$name) {
       global 
$rss_channel$currently_writing$item_counter;
       
$currently_writing "";
       if (
$name == "ITEM") {
           
$item_counter++;
       }
}

function 
characterData($parser$data) {
    global 
$rss_channel$currently_writing$main$item_counter;
    if (
$currently_writing != "") {
        switch(
$main) {
            case 
"CHANNEL":
                if (isset(
$rss_channel[$currently_writing])) {
                    
$rss_channel[$currently_writing] .= $data;
                } else {
                    
$rss_channel[$currently_writing] = $data;
                }
                break;
            case 
"IMAGE":
                if (isset(
$rss_channel[$main][$currently_writing])) {
                    
$rss_channel[$main][$currently_writing] .= $data;
                } else {
                    
$rss_channel[$main][$currently_writing] = $data;
                }
                break;
            case 
"ITEMS":
                if (isset(
$rss_channel[$main][$item_counter][$currently_writing])) {
                    
$rss_channel[$main][$item_counter][$currently_writing] .= $data;
                } else {
                    
$rss_channel[$main][$item_counter][$currently_writing] = $data;
                }
                break;
        }
    }
}

$xml_parser xml_parser_create();
xml_set_element_handler($xml_parser"startElement""endElement");
xml_set_character_data_handler($xml_parser"characterData");
if (!(
$fp fopen($file"r"))) {
    die(
"could not open XML input");
}

while (
$data fread($fp4096)) {
    if (!
xml_parse($xml_parser$datafeof($fp))) {
        die(
sprintf("XML error: %s at line %d",
                    
xml_error_string(xml_get_error_code($xml_parser)),
                    
xml_get_current_line_number($xml_parser)));
    }
}
xml_parser_free($xml_parser);

// output HTML
 
print ("<div class=\"channelname\">" $rss_channel["TITLE"] . "</div>"); 

if (isset(
$rss_channel["ITEMS"])) {
    if (
count($rss_channel["ITEMS"]) > 0) {
        for(
$i 0;$i count($rss_channel["ITEMS"]);$i++) {
            if (isset(
$rss_channel["ITEMS"][$i]["LINK"])) {
            print (
"\n<div class=\"itemtitle\">" $rss_channel["ITEMS"][$i]["TITLE"] . "</div>");
            } else {
            print (
"\n<div class=\"itemtitle\">" $rss_channel["ITEMS"][$i]["TITLE"] . "</div>");
            }
             print (
"<div class=\"itemdescription\">" $rss_channel["ITEMS"][$i]["DESCRIPTION"] . "</div><br />");         }
    } else {
        print (
"<b>There are no articles in this feed.</b>");
    }
}
print (
"<br/><span style='font-size:xx-small;'>www.nelsonk.com.ar</span>");
?>
El problema surge cuando le agrego un acento al codigo del blog. Por ejemplo "ó" me muestra "Ã" No entiendo que esta ocurriendo.

Desde ya muchas gracias

Última edición por Cluster; 26/04/2006 a las 14:37
  #2 (permalink)  
Antiguo 26/04/2006, 14:37
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
El problema que describes sucede por la codificación que usas .. el "char set" que llaman.

Prueba usando utf8_decode() .. ejemplo:

print ("<div class=\"itemdescription\">" . utf8_decode($rss_channel["ITEMS"][$i]["DESCRIPTION"]) . "</div><br />"); }

Un saludo,
__________________
Por motivos personales ya no puedo estar con Uds. Fue grato haber compartido todos estos años. Igualmente los seguiré leyendo.
  #3 (permalink)  
Antiguo 26/04/2006, 16:34
 
Fecha de Ingreso: marzo-2005
Mensajes: 49
Antigüedad: 19 años, 1 mes
Puntos: 2
Gracias

LO deje como me dijiste y andubo re bien gracias
  #4 (permalink)  
Antiguo 26/04/2006, 17:37
 
Fecha de Ingreso: enero-2006
Ubicación: mi casa
Mensajes: 255
Antigüedad: 18 años, 3 meses
Puntos: 0
yo tengo una duda..

No habría forma más sencilla de hacer un lector RSS?
  #5 (permalink)  
Antiguo 30/08/2007, 22:53
 
Fecha de Ingreso: junio-2004
Ubicación: Villa Carlos Paz
Mensajes: 88
Antigüedad: 19 años, 10 meses
Puntos: 2
Re: Leer rss con php

La verdad anda barbaro el script, pero queria saber que tengo que modificar para que los titulos de las noticias esten con los links que lleven a esas noticias.

:D Saludos
  #6 (permalink)  
Antiguo 26/10/2007, 09:47
Avatar de alamarcheta  
Fecha de Ingreso: mayo-2005
Ubicación: Isla Mêlée
Mensajes: 503
Antigüedad: 18 años, 11 meses
Puntos: 1
Hola. Tengo un problema y es el siguiente: En modo local me va perfecto pero cuando lo subo al servidor me tarda mucho y al final me da error no mostrando las noticias. He probado en dos dominios diferentes y nada. Lo que si están hospedados en el mismo hosting. ¿Os ha ocurrido alguna vez?
La verdad me estoy volviendo loco, che.
Saludos y gracias.
  #7 (permalink)  
Antiguo 26/10/2007, 12:45
(Desactivado)
 
Fecha de Ingreso: diciembre-2006
Mensajes: 225
Antigüedad: 17 años, 4 meses
Puntos: 1
Re: Leer rss con php

lo probe con las rss de metacafe y funciona perfectamente
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Tema Cerrado

SíEste tema le ha gustado a 1 personas (incluyéndote)




La zona horaria es GMT -6. Ahora son las 00:54.