PHP 4.0 Bug #2331: XML function handlers and tagname...
| From: | bago at datasail dot net | Date: | Mon, 20 Sep 1999 07:54:51 +0000 |
| Subject: | PHP 4.0 Bug #2331: XML function handlers and tagname... | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-11082@lists.php.net to get a copy of this message | ||
From: bago@datasail.net
Operating system: FreeBSD 3.2
PHP version: 4.0 Latest CVS (20/09/1999)
PHP Bug Type: Other
Bug description: XML function handlers and tagname...
try this code with a valid default.xml with some xml code.
it works fine with php3 and not with php4....
i get it to work with php4 too by adding " to $tgname as in the commented line.
i think it's a bug.... or it should be documented in the incompatibility list...
<?
$level = 0;
$tagname = array();
function XMLFstart($parser, $tgname, $attrs) {
$GLOBALS['level']++;
$GLOBALS['tagname'][$GLOBALS['level']] = $tgname;
# $GLOBALS['tagname'][$GLOBALS['level']] = "$tgname";
print('<'.$GLOBALS['tagname'][$GLOBALS['level']].'>');
}
function XMLFend($parser, $tgname) {
$GLOBALS['level']--;
print('</'.$GLOBALS['tagname'][$GLOBALS['level']].'>');
}
function XMLFparse($file) {
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "XMLFstart", "XMLFend");
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
$fp = fopen($file, "r");
while ($data = fread($fp, filesize($file))) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("<BR><BR>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);
fclose($fp);
}
XMLFparse('./default.xml');
?>