I got this example from Beginning PHP 4.  Unfortunately, I cant get to 
wrox's site to see if there were any errata updates for this piece of 
code, but for the life of me, I dont know whats wrong with it.  All its 
displaying is '-'.  If anyone could direct me to where its broken, Ill 
be very grateful..
------------------------------------------------
<?php

if (!($fp = fopen("http://freshmeat.net/backend/fm.rdf";, "r"))) 
die("Cant fetch");

$item_counter = 0;
$in_item_tag = 0;
$fm_current_tag_state = '';
$fm_headline_data = array();

function startElementHandler($parser, $element_name, $element_attribs) {
    global $item_counter, $in_item_tag, $fm_current_tag_state, 
$fm_headline_data;
    if ($element_name == "ITEM") {
        $in_item_tag = 1;
    }

    if ($in_item_tag == 1) {
        $fm_curent_tag_state = $element_name;
    } else {
        $fm_current_tag_state = '';
    }
}

function endElementHandler($parser, $element_name) {
    global $item_counter, $in_item_tag, $fm_current_tag_state, 
$fm_headline_data;
    $fm_current_tag_state = '';
    if ($element_name == "ITEM") {
        $item_counter++;
        $in_item_tag = 0;
    }
}

function characterDataHandler($parser, $data) {
    global $itme_counter, $in_item_tag, $fm_current_tag_state, 
$fm_headline_data;

    if ($fm_current_tag_state == '' || $in_item_tag == 0) return;

    if ($fm_current_tag_state == "TITLE") 
$fm_headline_data[$item_counter]['title'] = $data;

    if ($fm_current_tag_state == "LINK") 
$fm_headline_data[$item_counter]['link'] = $data;

    if ($fm_current_tag_state == "DESCRIPTION") 
$fm_headline_data[$item_counter]['description'] = $data;
}

if (!($xml_parser = xml_parser_create())) die("Parser Problem");

xml_set_element_handler($xml_parser, "startElementHandler", 
"endElementHandler");
xml_set_character_data_handler($xml_parser, "characterDataHandler");

while ($data = fread($fp, 4096)) {
    if (!xml_parse($xml_parser, $data, feof($fp))) {
        break;
    }
}

xml_parser_free($xml_parser);

for($i=0; $i < $item_counter; $i++) {
    printf("<a href=\"%s\">%s</a> - %s<br>\n", 
$fm_headlines_data[$i]['link'],
                                               
$fm_headlines_data[$i]['title'],
                                               
$fm_headlines_data[$i]['description']
                                               );
}

?>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to