Hi
u try to parse news from bbc from a rss page on the site...but nothing appears as output...
Any idea?
<?php
/*
Include this file in the script you want to display the BBCi world news.
e.g. require("news.php");
The data will be placed in the array $ndata, with the following structure
$ndata[$n]['title'] - contains the title of the news piece
$ndata[$n]['desc'] - contains the description of the news piece
$ndata[$n]['link'] - contains the link to the news piece
*/
switch ($name) {
case "ITEM":
$write = "false";
$initem = false;
$artcount++;
break;
default:
$write = "false";
break;
}
}
}
function characterData($parser, $data) {
global $write;
global $writeto;
global $ndata;
global $initem;
global $artcount;
if ($initem == true) {
if ($write == "true") {
$ndata[$artcount][$writeto] = $data;
}
}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
?>