Foros del Web » Programando para Internet » PHP »

(ayuda) RSS agregar fecha del post

Estas en el tema de (ayuda) RSS agregar fecha del post en el foro de PHP en Foros del Web. Hola, en este lector de rss en PHP, me gustaria poder incorporar a demas de el titular con el vinculo, la fecha en que se ...
  #1 (permalink)  
Antiguo 21/06/2008, 14:15
 
Fecha de Ingreso: marzo-2008
Mensajes: 1.020
Antigüedad: 16 años, 1 mes
Puntos: 21
(ayuda) RSS agregar fecha del post

Hola, en este lector de rss en PHP, me gustaria poder incorporar a demas de el titular con el vinculo, la fecha en que se posteo la entrada...es posible? como?

Código PHP:
<?php 
header
('Content-Type: text/html; charset=UTF-8');      
    class 
RssReader 
        var 
$url
        var 
$data
        
        function 
RssReader ($url){ 
            
$this->url
            
$this->data implode (""file ($url)); 
        } 
        
        function 
get_items (){ 
            
preg_match_all ("/<item .*>.*<\/item>/xsmUi"$this->data$matches); 
            
$items = array (); 
            foreach (
$matches[0] as $match){ 
                
$items[] = new RssItem ($match); 
            } 
            return 
$items
        } 
    } 
    
    class 
RssItem 
        var 
$title$url$description
        
        function 
RssItem ($xml){ 
            
$this->populate ($xml); 
        } 
        
        function 
populate ($xml){ 
            
preg_match ("/<title> (.*) <\/title>/xsmUi"$xml$matches); 
            
$this->title $matches[1]; 
            
preg_match ("/<link> (.*) <\/link>/xsmUi"$xml$matches); 
            
$this->url $matches[1]; 
            
preg_match ("/<description> (.*) <\/description>/xsmUi"$xml$matches); 
            
$this->description $matches[1]; 
    } 
        
    function 
get_title (){ 
        return 
$this->title
        } 
    
        function 
get_url (){ 
        return 
$this->url
        } 
        
        function 
get_description (){ 
            return 
$this->description
        } 
    } 

$rss = new RssReader ("http://www.nutrimel.com.ar/modulos/blog/?feed=rss2"); 
    
    foreach (
$rss->get_items () as $item){ 
        
printf ('<a href="%s">%s</a><br />%s<br /><br />'
        
$item->get_url (), $item->get_title (), $item->get_description ()); 
    } 
?>
saludos
  #2 (permalink)  
Antiguo 21/06/2008, 14:41
Avatar de Blunk  
Fecha de Ingreso: septiembre-2006
Mensajes: 145
Antigüedad: 17 años, 7 meses
Puntos: 4
Respuesta: (ayuda) RSS agregar fecha del post

preg_match ("/<pubDate> (.*) <\/pubDate>/xsmUi", $xml, $matches);
$this->description = $matches[1];
Igualmente depende del RSS que estes leyendo... algunos usan pubDate otros Date etc...
Me parece que la forma que los lee no es la mejor. Hay que tener en cuenta que los RSS son XML entonces lo mejor es usar el SimpleXML. Busca en google que aparece ;)
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 11:52.