php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #3937 with xml: can't read variable value inside if
Submitted: 2000-03-27 11:01 UTC Modified: 2001-02-10 16:31 UTC
From: akl at zodiac dot mimuw dot edu dot pl Assigned:
Status: Closed Package: Parser error
PHP Version: 3.0.15 OS: Linux RedHat 6.0
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: akl at zodiac dot mimuw dot edu dot pl
New email:
PHP Version: OS:

 

 [2000-03-27 11:01 UTC] akl at zodiac dot mimuw dot edu dot pl
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);

?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-10 16:31 UTC] jimw@php.net
works for me with 4.0.5-dev. i assume something else is going on, or this was fixed along the way.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Mar 18 08:01:29 2025 UTC