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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 15:01:28 2024 UTC