HI i have made a little simple script to get the nesw from freshmeat, the problem is that the var $data seens to desapear, please see the code below 🙂
<?
$file = "http://64.28.67.35/backend/fm-releases.rdf";
$currentTag = '';
$valigTag = FALSE;
function startElement($parser, $name, $attr) {
global $currentTag;
global $validTag;
$currentTag = $name;
//do nothing for now
}
function endElement($parser, $name) {
global $currentTag;
if ($currentTag == "ITEM") {
///echo ("<br>");
}
$currentTag = '';
}
function characterData($parser, $data) {
global $currentTag;
//echo $data; <- show correct value of $data
if ($currentTag == "ITEM") {
echo ("CurrentTag: $currentTag ");
echo "<b>validida</b> ";
echo $data."<br>\n"; // <-- here $data == '' WHY ?????
}
}
$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 ("Unable to open $file");
}
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);
?>
Thanks for your help
Marco