views:

12

answers:

1

(or Here are the code essentials:

$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??
    }
}

I am trying to append the path to host like this to create a one-line URL, because xmlparse puts a newline after each echo. So alternately, if anyone could tell me how to prevent the newline, that would solve my problem too!

By the way:

  • I also tried referencing the super-global $GLOBALS['host'] with the same result
  • I only have PHP4 available from my host server (otherwise I'd use SimpleXML)

Thanks, bob

A: 

Try to use superglobal $GLOBALS['host'] its faster anyway. Here is your fixed code

$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;      
    }
}
streetparade
Thank-you, but I had tried that also with the same results.
bob quinn