English 中文(简体)
PHP XML教区:变数每使用一次?
原标题:PHP XML parsing: variable is reset every time it s used?

这项职能总是每当它要求启动(启动)职能时,就拿出一个表格。 当它产生价值时,它总是在从一开始就显示出来的1美元,在从一站起就显示的1美元。 为什么没有全球美元?

$parser = xml_parser_create();
$tabs = 0;

function start($parser, $element_name, $element_attrs) {
    $tabs = $tabs + 1;
    echo str_repeat("	", $tabs).$element_name.": ";
}
function stop($parser, $element_name) {
    $tabs = $tabs - 1;
    echo "<br />";
}
function char($parser, $data) {
    echo $data;
}
xml_set_element_handler($parser, "start", "stop");
xml_set_character_data_handler($parser, "char");

$fp = fopen("$SignedRequest", "r");

while ($data = fread($fp, 4096)) {
    xml_parse($parser, $data, feof($fp)) or die (sprintf("XML Error: %s at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)));
}

xml_parser_free($parser);
最佳回答

无,购买力平价不必申报全球变量,如:

function start($parser, $element_name, $element_attrs) {
global $tab;
    $tabs = $tabs + 1;
    echo str_repeat("	", $tabs).$element_name.": ";
}

function stop($parser, $element_name) {
global $tab;
    $tabs = $tabs - 1;
    echo "<br />";
}
问题回答

You forgot

global $tabs;

在您的起首和起职时。 购买力平价变量只有“当地”变量,除非你明确标明其为全球变量。





相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

How to get instance from string in C#?

Is it possible to get the property of a class from string and then set a value? Example: string s = "label1.text"; string value = "new value"; label1.text = value; <--and some code that makes ...

XML DOM parsing br tag

I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...

Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

Locating specific string and capturing data following it

I built a site a long time ago and now I want to place the data into a database without copying and pasting the 400+ pages that it has grown to so that I can make the site database driven. My site ...

热门标签