(或以下是代码要点:
$host = "";
...
xml_set_character_data_handler($xmlparser, "tagContents");
...
function tagContents($parser, $data) {
global $current;
global $host;
if ($current == "HOST") {
$host = $data; // Trying to store a global here
}
if ($current == "PATH") {
echo $host.$data; // But its null when I get here. WHY??
}
}
我正在尝试将路径附加到此类主机以创建单行URL,因为xmlparse在每个回显之后放置一个换行符。所以换句话说,如果有人能告诉我如何防止换行,那也可以解决我的问题!
顺便说一下:
谢谢, 鲍勃
答案 0 :(得分:0)
无论如何,尽量使用超全球$ GLOBALS ['host']。这是您的固定代码
$host = "";
...
xml_set_character_data_handler($xmlparser, "tagContents");
...
function tagContents($parser, $data)
{
global $current;
if ($current == "HOST") {
$GLOBALS['host'] = $data; // Trying to store a global here
}
if ($current == "PATH") {
echo $GLOBALS['host'].$data;
}
}