Ver Mensaje Individual
  #4 (permalink)  
Antiguo 10/03/2005, 09:03
Avatar de yuguilley
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/titulares.php

luego crea un archivo llamado titulares.php y pega este codigo

y confira la siguiente linea con tu proveedor de noticias XMl o Rss

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

<?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);
?>

****************************-------------***************

Luego en su index.php inserta esto:

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

y dondequiera que te salga los titulares pega esto

<?php echo $programs;?>

Espero que sea lo que buscas