devWhiz Posted April 15, 2011 Share Posted April 15, 2011 Ok so I have a url that is an XML doc, it says at the top "This XML file does not appear to have any style information associated with it. The document tree is shown below." and it has info like this <outer> <xml> <viewer> <user> <id>1245789</id> <name>CLueless</user> <business>none</business> </user> </viewer> </xml> </outer> How would I load the link and then assign everything to a variable like id, name and business I usually use something like this but Im trying to get learn simple xml $info = file_get_contents('url'); $id = explode('<id>', $info); $id = explode('</', $id[1]); $name = explode('<name>', $info); $name = explode('</', $name[1]); $biz = explode('<business>', $info); $biz = explode('</', $biz); Quote Link to comment Share on other sites More sharing options...
requinix Posted April 15, 2011 Share Posted April 15, 2011 Okay, so... what have you tried so far? Quote Link to comment Share on other sites More sharing options...
devWhiz Posted April 15, 2011 Author Share Posted April 15, 2011 Nothing, I go off of examples, can you post an example for me? Quote Link to comment Share on other sites More sharing options...
harristweed Posted April 15, 2011 Share Posted April 15, 2011 note you have a tag mismatch "<name>CLueless</user>" <?php $xml_feed="<outer> <xml> <viewer> <user> <id>1245789</id> <name>CLueless</name> <business>none</business> </user> </viewer> </xml> </outer> "; if(!$xml = simplexml_load_string("$xml_feed")){ echo "Can't connect to feed $xml_feed"; }else{ foreach ($xml->xml->viewer->user as $value){ $id=$value->id; $name=$value->name; $biz=$value->business; echo"id=$id<br />\n"; echo"name=$name<br />\n"; echo"biz=$biz<br />\n"; } } ?> Quote Link to comment Share on other sites More sharing options...
devWhiz Posted April 16, 2011 Author Share Posted April 16, 2011 $xmll = file_get_contents('http://mob-dynamic-lb5.mobsters04.com/mob/refresh_stat_manual?user_id=496046235&session_id='); $xml = simplexml_load_string($xmll); foreach ($xml->xml->viewer->user as $value){ $id=$value->user_name; $name=$value->user_id; $biz=$value->error; echo"id=$id<br />\n"; echo"name=$name<br />\n"; echo"biz=$biz<br />\n"; sleep(10000); } what am I doing wrong Quote Link to comment Share on other sites More sharing options...
devWhiz Posted April 16, 2011 Author Share Posted April 16, 2011 $xmll = file_get_contents('http://mob-dynamic-lb5.mobsters04.com/mob/refresh_stat_manual?user_id=496046235&session_id='); $xml = simplexml_load_string($xmll); foreach ($xml->xml->viewer->user as $value){ $id=$value->id; $name=$value->name; $error=$value->error; echo"id=$id<br />\n"; echo"name=$name<br />\n"; echo"error=$error<br />\n"; sleep(10000); } what am I doing wrong Quote Link to comment Share on other sites More sharing options...
devWhiz Posted April 16, 2011 Author Share Posted April 16, 2011 got it, nevermind.. Thanks for the help!!! 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.