Foros del Web » Programando para Internet » PHP »

rss en mi web

Estas en el tema de rss en mi web en el foro de PHP en Foros del Web. Hola Me gustaria saber como puedo poner el siguiente archivo en mi web: http://www.wunderground.com/auto/rss...ions/60040.xml Me ha dicho k es necesario php y yo no tengo ...
  #1 (permalink)  
Antiguo 14/03/2005, 14:01
 
Fecha de Ingreso: junio-2004
Mensajes: 20
Antigüedad: 19 años, 10 meses
Puntos: 0
rss en mi web

Hola

Me gustaria saber como puedo poner el siguiente archivo en mi web:

http://www.wunderground.com/auto/rss...ions/60040.xml

Me ha dicho k es necesario php y yo no tengo ni idea de php. mi pegunta es si es muy dificil, si no me gustaria que alguien me explicaa como empezar. y y si ademas es posible configurar una ez acoplado a mi pagina es archivo,

muchas gracias


www.ilanzarote.net
  #2 (permalink)  
Antiguo 14/03/2005, 16:22
Avatar de yuguilley  
Fecha de Ingreso: febrero-2004
Ubicación: Montenegro Quindío
Mensajes: 108
Antigüedad: 20 años, 2 meses
Puntos: 0
Prueba este codigo si te sirve

crea una carpeta ej. include/tiempo.php.

Crea un archivo llamado tiempo.php y guardalo en la carpeta include y pega este codigo

<?php

// array to convert XML entities into text
$xmlreplace = array(
'&amp;' => '&',
'&lt;' => '<',
'&gt;' => '>',
'&apos;' => '\'',
'&quot;' => '"',
);

// opening element handler
function startElement($parser, $name, $attrs) {

global $cdata, $item, $curTag, $a;

$curTag .= "$name|";

$cdata = "";

if($curTag == "RSS|CHANNEL|ITEM|") {
$a++;
}
}

//closing element handler
function endElement($parser, $name) {
// Notice that we call the same global variables here
// that we called in the opening tag function, save $feed:
global $cdata, $feed, $item, $curTag, $a;


switch($curTag) {
case "RSS|CHANNEL|TITLE|":
$feed['title'] = $cdata;
break;
case "RSS|CHANNEL|LINK|":
$feed['link'] = $cdata;
break;
case "RSS|CHANNEL|DESCRIPTION|":
$feed['description'] = $cdata;
break;
case "RSS|CHANNEL|PUBDATE|":
$feed['pubdate'] = $cdata;
break;
case "RSS|CHANNEL|IMAGE|URL|":
$feed['image'] = $cdata;
break;
case "RSS|CHANNEL|IMAGE|WIDTH|":
$feed['img_width'] = $cdata;
break;
case "RSS|CHANNEL|IMAGE|HEIGHT|":
$feed['img_height'] = $cdata;
break;
case "RSS|CHANNEL|ITEM|TITLE|":
$item[$a]['title'] = $cdata;
break;
case "RSS|CHANNEL|ITEM|CATEGORY|":
$item[$a]['category'] = $cdata;
break;
case "RSS|CHANNEL|ITEM|LINK|":
$item[$a]['link'] = $cdata;
break;
case "RSS|CHANNEL|ITEM|DESCRIPTION|":
$item[$a]['description'] = $cdata;
}

$temp = explode("|", $curTag);
$temp2 = array_pop($temp);
$temp2 = array_pop($temp);
$curTag = implode("|", $temp);
$curTag .= "|";
}

function characterData($parser, $data) {
global $cdata, $xmlreplace;
$cdata .= strtr($data, $xmlreplace);
}
/*
OK, with the XML handler functions out of the way, we're now ready to parse the RSS feed.
First, we need to get the RSS feed from WAGM's Web site, which we do with fopen:
*/

$fp = fopen("http://www.ibs.org/dm/syndicate/rss/niv.xml", "r");
if(!$fp) {
die("<p>Cannot open RSS feed.</p>");
}
else {
//read RSS document into variable
while(!feof($fp)) {
$data .= fgets($fp, 2048);
}

// create XML parser, set handlers (the functions we created above):
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");

if (xml_parse($xml_parser, $data)) {
$news = "<dl>";
$sports = "<dl>";
$weather = "<dl>";
$programs = "<dl>";

foreach($item as $current) {
switch($current[category]) {

default:
$programs .= "<dt>$current[title]</dt>\n";
$programs .= "<dd>$current[description]<br>\n";
$programs .= "<a href=\"$current[link]\" target='_blank'></a></dd>\n";
}
}
$news .= "</dl>";
$sports .= "</dl>";
$weather .= "</dl>";
$programs .= "</dl>";
}
else {
//die on failed XML parse, display error message
$error_msg = "<p>Cannot parse XML document: $station_url; error: "
.xml_error_string(xml_get_error_code($xml_parser)) .", line "
.xml_get_current_line_number($xml_parser)."</p>";
die($error_msg);
}
xml_parser_free($xml_parser);
}

//close RSS feed
fclose($fp);
?>

****************************-------------***************
y configura la siguiente linea, coloca la direccion URL de tu proveedor del Tiempo en XMl o Rss

------------------------------------------------------

$fp = fopen("http://www.ibs.org/dm/syndicate/rss/niv.xml", "r");
if(!$fp) {
die("<p>Cannot open RSS feed.</p>");

--------------------------------------------------

****************************-------------***************
Luego en su index.php inserta esto:


<?php require("include/tiempo.php"); ?>


y dondequiera que te salga el estado del tiempo pega esto


<?php echo $weather;?>


Espero que sea lo que buscas.

Última edición por yuguilley; 14/03/2005 a las 17:24
  #3 (permalink)  
Antiguo 14/03/2005, 19:23
 
Fecha de Ingreso: junio-2004
Mensajes: 20
Antigüedad: 19 años, 10 meses
Puntos: 0
Muchas gracias, espero k sea lo k busco.

Lo he probado pero no me funciona, es k no tengo ni idea de php. Aunke he hecho como tu has explicado, pero no me va.

Si lo me lo pudieras explicar de una manera mas sencilla, si eso es posible.
pero muchas gracias de todas formas pork ya se por lo menos por donde empezar.
  #4 (permalink)  
Antiguo 14/03/2005, 19:38
Avatar de FuLaNo_  
Fecha de Ingreso: mayo-2003
Ubicación: Don Torcuato, Buenos Aires, Argentina
Mensajes: 1.250
Antigüedad: 21 años
Puntos: 2
Antes que nada, en el servidor donde esta alojado tu sitio, tienes soporte php?
__________________
I Love Programming...
  #5 (permalink)  
Antiguo 15/03/2005, 08:58
 
Fecha de Ingreso: junio-2004
Mensajes: 20
Antigüedad: 19 años, 10 meses
Puntos: 0
si con mysql
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:08.