I can’t really seem to read my XML file and get the data. Or, really, I can’t seem to read the data and put it in a var.
Below is my php file, and below that is my xml file.
[code=php]
<?php
$name = “Foo”;
$redirvars = “user=Foo&id=Foo”;
$holdsendurl .= “http://www.foo.com/welcome.html?” . “{$redirvars}”;
$default_dir = “loggedusers.xml”;
$xmlstr = simplexml_load_file($default_dir);
//var_dump($xmlstr);
$dom = new domDocument;
$dom->loadXML($xmlstr);
$s_dom = simplexml_import_dom($dom);
$usrstr = “”;
foreach($s_dom->loggeduser[0]->username as $gname)
{
$usrstr .= “<username>” . “{$gname}” . “</username>”;
}
$usrstr .= “<username>” . “{$name}” . “</username>”;
$xmlstr = “<?xml version=’1.0′ encoding=’UTF-8′ ?><loggeduser>” . “{$usrstr}” . “</loggeduser>”;
$dom2 = new domDocument;
$dom2->loadXML($xmlstr);
$test = $dom2->save(“loggedusers.xml”);
echo “<br>hello World!<br><br><textarea>”.$usrstr.”</textarea>”;
?>
[code=php]
<?xml version=”1.0″ encoding=”UTF-8″?>
<loggeduser>
<username>Foo</username>
</loggeduser>
Whenever the php runs, it will simply save this exact file, but it should add a ‘Foo’ user to the list. Or at least that is what I want it to do.
It seems that it does not read the ‘username’ and get the list of users, then save them to the variable for me to save again.
any ideas?