Darla Posted February 13, 2007 Share Posted February 13, 2007 Hello I am kindof a newbie on this so bare with me.. I have used xml_parser to read some xml and put the values in an array using xml_parse_into_struct. This xml is stored in $results. I get the values when doing this: print_r($results); However, I'd like to get my hands on some of the simple values from the xml in neat variables so I can further put them into a db. I have tried accessing the values like this: echo $results[0]; echo $results["boat"]; echo $results['boat']; But all it returns is a simple 'A'. Great if someone could give me a tip on this. Also, I am wondering what is the best way to fetch xml: xml_parse, DOM or simplexml? Darla Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 13, 2007 Share Posted February 13, 2007 Can you show us what you get when you do the print_r()? Quote Link to comment Share on other sites More sharing options...
Darla Posted February 13, 2007 Author Share Posted February 13, 2007 Like this: Array ( [0] => Array ( [tag] => TRANSPORTATION [type] => open [level] => 1 [value] => ) [1] => Array ( [tag] => BOAT [type] => complete [level] => 2 [value] => 6 ) ... Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 13, 2007 Share Posted February 13, 2007 there is no value with the key of boat. What are you trying to get? So it tries to get the first letter of the string $results, which is A. Quote Link to comment Share on other sites More sharing options...
Darla Posted February 13, 2007 Author Share Posted February 13, 2007 I am trying to get the value 6.. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 13, 2007 Share Posted February 13, 2007 So the one with BOAT in it is $boat = $results[1]; Then six is $boat['value']; Quote Link to comment Share on other sites More sharing options...
Darla Posted February 13, 2007 Author Share Posted February 13, 2007 did not seem to work, [value] => 6 is the one I am trying to get, this is what you meant too right? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 13, 2007 Share Posted February 13, 2007 Yes, what did it show when you used what I wrote? Post your new code and the results. Quote Link to comment Share on other sites More sharing options...
Darla Posted February 13, 2007 Author Share Posted February 13, 2007 I get an output of a simple "r", my code was like you said: $boat= $results[1]; echo $boat['value']; Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 13, 2007 Share Posted February 13, 2007 It looks like whenever you try to use $results, it's saying it's a string. What happens when you print count($results), or try to do a foreach($results AS $r){ } Quote Link to comment Share on other sites More sharing options...
Darla Posted February 13, 2007 Author Share Posted February 13, 2007 ahh I found it - seems it was set to the variable $results later - it was supposed to be a table but turns out it was a string, when I tried the originale table name it worked Sorry to have bothered you and thanks for helping!! Btw: what do you prefer when fetching from xml? simple_xml, dom or parse_xml? Have a nice evening! Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 13, 2007 Share Posted February 13, 2007 I've never done it, so I can't say which I prefer. By the way, those are arrays, not tables. MySQL and HTML can have tables, but PHP doesn't...what you have there is an array. Quote Link to comment Share on other sites More sharing options...
Darla Posted February 13, 2007 Author Share Posted February 13, 2007 ok, yes arrays was what I meant Thanks again for helping, you saved my day! Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 13, 2007 Share Posted February 13, 2007 No problems. Hit the SOLVED button 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.