devWhiz Posted June 5, 2011 Share Posted June 5, 2011 Well I cant get simplexml to parse out the xml I need correctly, I tried to call out multi entrys in the xml and print them out in CLI and I only get the first letter of a couple of the strings.. $LoadXML = file_get_contents("xmldoc.xml"); $xml = simplexml_load_string($LoadXML); foreach($xml->xml->user as $entry) { $ID = $entry->id; $name = $entry->name; $age = $entry->age; } for($x=0; $x!=count($entry)-1; $x++) { echo $ID[$x]."\n"; echo $name[$x]."\n"; echo $age[$x]."\n"; } The code above only echos the last entry of the user.. here is the xml <outer> <xml> <user> <id>123456</id> <name>Clueless</name> <age>18</age> </user> <user> <id>234566</id> <name>AnotherName</name> <age>21</age> </user> <user> <id>1232426</id> <name>YetAnother</name> <age>22</age> </user> </xml> </outer> outputs 1232426 YetAnother 22 Quote Link to comment Share on other sites More sharing options...
RussellReal Posted June 5, 2011 Share Posted June 5, 2011 you have the for loop outside of the foreach loop.. Quote Link to comment Share on other sites More sharing options...
xyph Posted June 5, 2011 Share Posted June 5, 2011 You want to tell PHP that the variables will hold arrays using $ID = array(); $name = array(); $age = array(); Declare that before you populate them. Populate them using this instead. $ID[] = $entry->id; $name[] = $entry->name; $age[] = $entry->age; Leaving the key blank will tell the engine to automatically call array_push() and add the value to a new key at the end of the array. Your script should work fine. Not a simplexml issue. Quote Link to comment Share on other sites More sharing options...
devWhiz Posted June 5, 2011 Author Share Posted June 5, 2011 DOH!, I forgot to put the [] in each variable, thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.