NYCPHP Meetup

NYPHP.org

[nycphp-talk] xml_parse and CLI

Matthew Terenzio matt at jobsforge.com
Sat Aug 13 00:30:00 EDT 2005


This block of code works fine on a web server, but fails with:

XML error: XML declaration not finished at line 1

on CLI. Anyone understand why? The $data variable does in fact look 
like the remote XML doc, so the fopen and fread seem to be working.

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




More information about the talk mailing list