Bug #3937: with xml: can't read variable value inside if
| From: | akl at zodiac dot mimuw dot edu dot pl | Date: | Mon, 27 Mar 2000 16:01:45 +0000 |
| Subject: | Bug #3937: with xml: can't read variable value inside if | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-17285@lists.php.net to get a copy of this message | ||
From: akl@zodiac.mimuw.edu.pl
Operating system: Linux RedHat 6.0
PHP version: 3.0.15
PHP Bug Type: Parser error
Bug description: with xml: can't read variable value inside if
I have a file.xml with <EMAIL>char_data</EMAIL>. Calling the script: http://server/script.php3?file.xml . In function
characterData variable $data is empty when it's echoed inside if:
<?php
$filename = $argv[0];
$double = FALSE;
function startElement($parser, $name, $attribs)
{
global $double;
echo "<DIV CLASS=\"$name\">\n";
if ($name == "EMAIL")
$double = TRUE;
/* string inside <EMAIL></EMAIL> has to be displayed twice */
}
function endElement($parser, $name)
{
echo "</DIV>\n";
}
function characterData($parser, $data)
{
global $double;
if ($double)
{
echo "IF: ","$data"," :ENDIF";
/* IF: and ENDIF: are displayed but $data is empty */
$double = FALSE;
}
echo "$data"; /* here $data is ok*/
}
$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($file = fopen($filename, "r")))
die("could not open XML input");
while ($data = fread($file, 4096))
{
if (!xml_parse($xml_parser, $data, feof($file)))
{
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);
?>