【发布时间】:2010-03-02 20:39:45
【问题描述】:
(或者这里是代码要点:
$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 在每个回显之后都会添加一个换行符。因此,如果有人能告诉我如何防止换行符,那也可以解决我的问题!
顺便说一句:
- 我也尝试过引用超级全局 $GLOBALS['host'] 得到相同的结果
- 我的主机服务器只有 PHP4 可用 (otherwise I'd use SimpleXML)
谢谢, 鲍勃
【问题讨论】:
标签: php global-variables xml-parsing