Ver Mensaje Individual
  #2 (permalink)  
Antiguo 03/02/2005, 21:59
RakoVky
 
Fecha de Ingreso: diciembre-2002
Mensajes: 100
Antigüedad: 21 años, 4 meses
Puntos: 1
Saludos desde Venezuela...

Esto de las RSS( Really Simple Syndication ) Te permitira tener información actualizada de otros sitios que dispongan de esta alternativa ejemplo este Foro, si observas en la parte inferior [RSS] en Naranja ...

Como puedo implementarlo en mi WEB

A ver:

Estas en un server con Soporte PHP?

Si la respuesta es si:

Script Ejemplo:

(getpost.php)

Código PHP:
<?php
function GetXMLTree ($xmldata)
{
    
// we want to know if an error occurs
    
ini_set ('track_errors''1');

    
$xmlreaderror false;

    
$parser xml_parser_create ('ISO-8859-1');
    
xml_parser_set_option ($parserXML_OPTION_SKIP_WHITE1);
    
xml_parser_set_option ($parserXML_OPTION_CASE_FOLDING0);
    if (!
xml_parse_into_struct ($parser$xmldata$vals$index)) {
        
$xmlreaderror true;
        echo 
"error";
    }
    
xml_parser_free ($parser);

    if (!
$xmlreaderror) {
        
$result = array ();
        
$i 0;
        if (isset (
$vals [$i]['attributes']))
            foreach (
array_keys ($vals [$i]['attributes']) as $attkey)
            
$attributes [$attkey] = $vals [$i]['attributes'][$attkey];

        
$result [$vals [$i]['tag']] = array_merge ($attributesGetChildren ($vals$i'open'));
    }

    
ini_set ('track_errors''0');
    return 
$result;
}

function 
GetChildren ($vals, &$i$type)
{
    if (
$type == 'complete') {
        if (isset (
$vals [$i]['value']))
            return (
$vals [$i]['value']);
        else
            return 
'';
    }

    
$children = array (); // Contains node data

    /* Loop through children */
    
while ($vals [++$i]['type'] != 'close') {
        
$type $vals [$i]['type'];
        
// first check if we already have one and need to create an array
        
if (isset ($children [$vals [$i]['tag']])) {
            if (
is_array ($children [$vals [$i]['tag']])) {
                
$temp array_keys ($children [$vals [$i]['tag']]);
                
// there is one of these things already and it is itself an array
                
if (is_string ($temp [0])) {
                    
$a $children [$vals [$i]['tag']];
                    unset (
$children [$vals [$i]['tag']]);
                    
$children [$vals [$i]['tag']][0] = $a;
                }
            } else {
                
$a $children [$vals [$i]['tag']];
                unset (
$children [$vals [$i]['tag']]);
                
$children [$vals [$i]['tag']][0] = $a;
            }

            
$children [$vals [$i]['tag']][] = GetChildren ($vals$i$type);
        } else
            
$children [$vals [$i]['tag']] = GetChildren ($vals$i$type);
        
// I don't think I need attributes but this is how I would do them:
        
if (isset ($vals [$i]['attributes'])) {
            
$attributes = array ();
            foreach (
array_keys ($vals [$i]['attributes']) as $attkey)
            
$attributes [$attkey] = $vals [$i]['attributes'][$attkey];
            
// now check: do we already have an array or a value?
            
if (isset ($children [$vals [$i]['tag']])) {
                
// case where there is an attribute but no value, a complete with an attribute in other words
                
if ($children [$vals [$i]['tag']] == '') {
                    unset (
$children [$vals [$i]['tag']]);
                    
$children [$vals [$i]['tag']] = $attributes;
                }
                
// case where there is an array of identical items with attributes
                
elseif (is_array ($children [$vals [$i]['tag']])) {
                    
$index count ($children [$vals [$i]['tag']]) - 1;
                    
// probably also have to check here whether the individual item is also an array or not or what... all a bit messy
                    
if ($children [$vals [$i]['tag']][$index] == '') {
                        unset (
$children [$vals [$i]['tag']][$index]);
                        
$children [$vals [$i]['tag']][$index] = $attributes;
                    }
                    
$children [$vals [$i]['tag']][$index] = array_merge ($children [$vals [$i]['tag']][$index], $attributes);
                } else {
                    
$value $children [$vals [$i]['tag']];
                    unset (
$children [$vals [$i]['tag']]);
                    
$children [$vals [$i]['tag']]['value'] = $value;
                    
$children [$vals [$i]['tag']] = array_merge ($children [$vals [$i]['tag']], $attributes);
                }
            } else
                
$children [$vals [$i]['tag']] = $attributes;
        }
    }

    return 
$children;
}

//URL del archivo Xml - Lectura
$url "http://www.forosdelweb.com/index.xml"

//Resultado de Lectura:
$contents file_get_contents($url);
echo 
$data["rss"]["channel"]["description"];
echo 
"<br><br>";
$t count($data["rss"]["channel"]["item"]);
for(
$i 0$i $t$i++){
echo 
"<br><br>";
echo 
"<a href='" $data["rss"]["channel"]["item"][$i]["link"] . "' target='_blank'>" $data["rss"]["channel"]["item"][$i]["title"] . "</a>";
echo 
"<br>";
echo 
$data["rss"]["channel"]["item"][$i]["description"];
}
echo 
"<br><br>";

?>
Sube este script a tu server y te mostrara los ultimos post de este foro, ademas un limk para ir al hilo de cada uno...


Espero no haberte abrumado con esto, nec. aprender algun lenguaje de secuencia de comando (ASP - PHP) para sacar partido a los RSS...


Última edición por RakoVky; 03/02/2005 a las 22:01