Foros del Web » Programando para Internet » PHP »

rss y simplexml

Estas en el tema de rss y simplexml en el foro de PHP en Foros del Web. buenas: estoy tratando de leer este rss: http://www.softonic.com/rss/2/feed_l...actualized.xml de esta manera: Código PHP: $xml = simplexml_load_file ( 'http://www.softonic.com/rss/2/feed_last_news_by_date_actualized.xml' );      var_dump ( $xml );  y ...
  #1 (permalink)  
Antiguo 30/03/2008, 20:19
Avatar de destor77  
Fecha de Ingreso: noviembre-2004
Ubicación: Gálvez, Santa Fe, Argentina
Mensajes: 2.654
Antigüedad: 19 años, 5 meses
Puntos: 43
rss y simplexml

buenas:

estoy tratando de leer este rss: http://www.softonic.com/rss/2/feed_l...actualized.xml de esta manera:
Código PHP:
$xml=simplexml_load_file('http://www.softonic.com/rss/2/feed_last_news_by_date_actualized.xml');
    
var_dump($xml); 
y me devuelve esto:


object(SimpleXMLElement)#1 (2) { ["@attributes"]=> array(1) { ["version"]=> string(3) "2.0" } ["channel"]=> object(SimpleXMLElement)#2 (8) { ["title"]=> string(37) "Windows novedades (Windows): Softonic" ["description"]=> string(297) "El website hispano lÃ*der en descargas de shareware, freeware, juegos, salvapantallas y software gratis. Incluye emule, kazaa, divx, nero, winamp, mp3, msn messenger. Todo en español, más de 65.000 programas, 3.000 áreas, y soporte para Windows, Macintosh, Linux, Palm OS, Pocket PC y Móviles." ["pubDate"]=> string(31) "dom, 30 mar 2008 21:15:33 +0100" ["language"]=> string(5) "es-es" ["image"]=> object(SimpleXMLElement)#3 (3) { ["url"]=> string(50) "http://images.softonic.net/images/softonic_xml.gif" ["title"]=> string(71) "Softonic: emule, msn messenger, kazaa, nero, software, programas gratis" ["link"]=> string(50) "http://images.softonic.net/images/softonic_xml.gif" } ["link"]=> string(24) "http://www.softonic.com/" ["docs"]=> string(37) "http://blogs.law.harvard.edu/tech/rss" ["item"]=> array(20) { [0]=> object(SimpleXMLElement)#4 (6) { ["title"]=> object(SimpleXMLElement)#24 (0) { } ["link"]=> string(45) "http://firefox-portable-2-es-es.softonic.com/" ["description"]=> object(SimpleXMLElement)#25 (0) { } ["comments"]=> object(SimpleXMLElement)#26 (0) { } ["guid"]=> string(5) "57303" ["pubDate"]=> string(6) " +0100" } [1]=> object(SimpleXMLElement)#5 (6) { ["title"]=> object(SimpleXMLElement)#27 (0) { } ["link"]=> string(27) "http://xnview.softonic.com/" ["description"]=> object(SimpleXMLElement)#28 (0) { } ["comments"]=> object(SimpleXMLElement)#29 (0) { } ["guid"]=> string(5) "14433" ["pubDate"]=> string(6) " +0100" } [2]=> object(SimpleXMLElement)#6 (6) { ["title"]=> object(SimpleXMLElement)#30 (0) { } ["link"]=> string(26) "http://joost.softonic.com/" ["description"]=> object(SimpleXMLElement)#31 (0) { } ["comments"]=> object(SimpleXMLElement)#32 (0) { } ["guid"]=> string(5) "62130" ["pubDate"]=> string(6) " +0100" } [3]=> object(SimpleXMLElement)#7 (6) { ["title"]=> object(SimpleXMLElement)#33 (0) { } ["link"]=> string(29) "http://bitcomet.softonic.com/" ["description"]=> object(SimpleXMLElement)#34 (0) { } ["comments"]=> object(SimpleXMLElement)#35 (0) { } ["guid"]=> string(5) "35799" ["pubDate"]=> string(6) " +0100" } [4]=> object(SimpleXMLElement)#8 (6) { ["title"]=> object(SimpleXMLElement)#36 (0) { } ["link"]=> string(27) "http://winamp.softonic.com/" ["description"]=> object(SimpleXMLElement)#37 (0) { } ["comments"]=> object(SimpleXMLElement)#38 (0) { } ["guid"]=> string(5) "30100" ["pubDate"]=> string(6) " +0100" } [5]=> object(SimpleXMLElement)#9 (6) { ["title"]=> object(SimpleXMLElement)#39 (0) { } ["link"]=> string(34) "http://winamp-5-lite.softonic.com/" ["description"]=> object(SimpleXMLElement)#40 (0) { } ["comments"]=> object(SimpleXMLElement)#41 (0) { } ["guid"]=> string(5) "30671" ["pubDate"]=> string(6) " +0100" } [6]=> object(SimpleXMLElement)#10 (6) { ["title"]=> object(SimpleXMLElement)#42 (0) { } ["link"]=> string(31) "http://miranda-im.softonic.com/" ["description"]=> object(SimpleXMLElement)#43 (0) { } ["comments"]=> object(SimpleXMLElement)#44 (0) { } ["guid"]=> string(5) "13834" ["pubDate"]=> string(6) " +0100" } [7]=> object(SimpleXMLElement)#11 (6) { ["title"]=> object(SimpleXMLElement)#45 (0) { } ["link"]=> string(30) "http://uefa-euro.softonic.com/" ["description"]=> object(SimpleXMLElement)#46 (0) { } ["comments"]=> object(SimpleXMLElement)#47 (0) { } ["guid"]=> string(5) "70018" ["pubDate"]=> string(6) " +0100" } [8]=> object(SimpleXMLElement)#12 (6) { ["title"]=> object(SimpleXMLElement)#48 (0) { } ["link"]=> string(30) "http://inca-ball.softonic.com/" ["description"]=> object(SimpleXMLElement)#49 (0) { } ["comments"]=> object(SimpleXMLElement)#50 (0) { } ["guid"]=> string(5) "69963" ["pubDate"]=> string(6) " +0100" } [9]=> object(SimpleXMLElement)#13 (6) { ["title"]=> object(SimpleXMLElement)#51 (0) { } ["link"]=> string(25) "http://miro.softonic.com/" ["description"]=> object(SimpleXMLElement)#52 (0) { } ["comments"]=> object(SimpleXMLElement)#53 (0) { } ["guid"]=> string(5) "49476" ["pubDate"]=> string(6) " +0100" } [10]=> object(SimpleXMLElement)#14 (6) { ["title"]=> object(SimpleXMLElement)#54 (0) { } ["link"]=> string(26) "http://vlite.softonic.com/" ["description"]=> object(SimpleXMLElement)#55 (0) { } ["comments"]=> object(SimpleXMLElement)#56 (0) { } ["guid"]=> string(5) "64106" ["pubDate"]=> string(6) " +0100" } [11]=> object(SimpleXMLElement)#15 (6) { ["title"]=> object(SimpleXMLElement)#57 (0) { } ["link"]=> string(27) "http://prtscr.softonic.com/" ["description"]=> object(SimpleXMLElement)#58 (0) { } ["comments"]=> object(SimpleXMLElement)#59 (0) { } ["guid"]=> string(5) "70012" ["pubDate"]=> string(6) " +0100" } [12]=> object(SimpleXMLElement)#16 (6) { ["title"]=> object(SimpleXMLElement)#60 (0) { } ["link"]=> string(26) "http://wuala.softonic.com/" ["description"]=> object(SimpleXMLElement)#61 (0) { } ["comments"]=> object(SimpleXMLElement)#62 (0) { } ["guid"]=> string(5) "68968" ["pubDate"]=> string(6) " +0100" } [13]=> object(SimpleXMLElement)#17 (6) { ["title"]=> object(SimpleXMLElement)#63 (0) { } ["link"]=> string(46) "http://security-process-explorer.softonic.com/" ["description"]=> object(SimpleXMLElement)#64 (0) { } ["comments"]=> object(SimpleXMLElement)#65 (0) { } ["guid"]=> string(5) "70010" ["pubDate"]=> string(6) " +0100" } [14]=> object(SimpleXMLElement)#18 (6) { ["title"]=> object(SimpleXMLElement)#66 (0) { } ["link"]=> string(48) "http://office-clock-3d-screensaver.softonic.com/" ["description"]=> object(SimpleXMLElement)#67 (0) { } ["comments"]=> object(SimpleXMLElement)#68 (0) { } ["guid"]=> string(5) "69045" ["pubDate"]=> string(6) " +0100" } [15]=> object(SimpleXMLElement)#19 (6) { ["title"]=> object(SimpleXMLElement)#69 (0) { } ["link"]=> string(48) "http://free-window-registry-repair.softonic.com/" ["description"]=> object(SimpleXMLElement)#70 (0) { } ["comments"]=> object(SimpleXMLElement)#71 (0) { } ["guid"]=> string(5) "57402" ["pubDate"]=> string(6) " +0100" } [16]=> object(SimpleXMLElement)#20 (6) { ["title"]=> object(SimpleXMLElement)#72 (0) { } ["link"]=> string(33) "http://rank-tracker.softonic.com/" ["description"]=> object(SimpleXMLElement)#73 (0) { } ["comments"]=> object(SimpleXMLElement)#74 (0) { } ["guid"]=> string(5) "47783" ["pubDate"]=> string(6) " +0100" } [17]=> object(SimpleXMLElement)#21 (6) { ["title"]=> object(SimpleXMLElement)#75 (0) { } ["link"]=> string(40) "http://automation-anywhere.softonic.com/" ["description"]=> object(SimpleXMLElement)#76 (0) { } ["comments"]=> object(SimpleXMLElement)#77 (0) { } ["guid"]=> string(5) "38450" ["pubDate"]=> string(6) " +0100" } [18]=> object(SimpleXMLElement)#22 (6) { ["title"]=> object(SimpleXMLElement)#78 (0) { } ["link"]=> string(30) "http://konvertor.softonic.com/" ["description"]=> object(SimpleXMLElement)#79 (0) { } ["comments"]=> object(SimpleXMLElement)#80 (0) { } ["guid"]=> string(5) "10328" ["pubDate"]=> string(6) " +0100" } [19]=> object(SimpleXMLElement)#23 (6) { ["title"]=> object(SimpleXMLElement)#81 (0) { } ["link"]=> string(31) "http://fresh-view.softonic.com/" ["description"]=> object(SimpleXMLElement)#82 (0) { } ["comments"]=> object(SimpleXMLElement)#83 (0) { } ["guid"]=> string(5) "31360" ["pubDate"]=> string(6) " +0100" } } } }


yo quiero obtener:

["pubDate"]=> string(31) "dom, 30 mar 2008 21:15:33 +0100"

y :
["item"]=> array(20) { [0]=> object(SimpleXMLElement)#4 (6) { ["title"]=> object(SimpleXMLElement)#24 (0) { } ["link"]=> string(45) "http://firefox-portable-2-es-es.softonic.com/" ["description"]=> object(SimpleXMLElement)#25 (0) { } ["comments"]=> object(SimpleXMLElement)#26 (0) { } ["guid"]=> string(5) "57303" ["pubDate"]=> string(6) " +0100" } [1]=> object(SimpleXMLElement)#5 (6) { ["title"]=> object(SimpleXMLElement)#27 (0) { } ["link"]=> string(27) "http://xnview.softonic.com/" ["description"]=> object(SimpleXMLElement)#28 (0) { } ["comments"]=> object(SimpleXMLElement)#29 (0) { } ["guid"]=> string(5) "14433" ["pubDate"]=> string(6) " +0100" } [2]=> object(SimpleXMLElement)#6 (6) { ["title"]=> object(SimpleXMLElement)#30 (0) { } ["link"]=> string(26) "http://joost.softonic.com/" ["description"]=> object(SimpleXMLElement)#31 (0) { } ["comments"]=> object(SimpleXMLElement)#32 (0) { } ["guid"]=> string(5) "62130" ["pubDate"]=> string(6) " +0100" } ......

intente con
Código PHP:
$result $xml->xpath('//channel'); 
pero no puede acceder a los elementos de ese array que me genera, alguien me puede guiar un poco mas....

desde ya muchas gracias
  #2 (permalink)  
Antiguo 30/03/2008, 20:21
Avatar de destor77  
Fecha de Ingreso: noviembre-2004
Ubicación: Gálvez, Santa Fe, Argentina
Mensajes: 2.654
Antigüedad: 19 años, 5 meses
Puntos: 43
Re: rss y simplexml

bueno sin quererlo encontre la solución se la dejo para el que quiera usarla:

Código PHP:
$Noticias simplexml_load_file('http://www.softonic.com/rss/2/feed_last_news_by_date_actualized.xml');
    if (!
count((array)$Noticias->item))
    
//Si es 0 quiere decir que existe la etiqueta channel
    
{
        echo 
"Publicado el: ".$Noticias->channel->pubDate."<br>";
        foreach(
$Noticias->channel->item as $Noticia)
        {
            echo 
"titulo: ".utf8_decode($Noticia->title)."<br>";
            echo 
"description: ".utf8_decode($Noticia->description)."<br>";
        }
    }
    else
    {
        foreach(
$Noticias->item as $Noticia)
        {
            echo 
"titulo: ".utf8_decode($Noticia->title)."<br>";
            echo 
"description: ".utf8_decode($Noticia->description)."<br>";

        }
    } 
saludos
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.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:36.