G-NEWC Posted August 11, 2009 Report Posted August 11, 2009 Hi Guys, I Have this code to connect to the XML document on our FShost server, but it is not displaying each player, only one...if anyone could edit to suit, or explain to me why this is happening it would be great. <?php // XML Page $feed_url = "http://64.22.78.67:98/xml"; # INITIATE CURL. $curl = curl_init(); # CURL SETTINGS. curl_setopt($curl, CURLOPT_URL,"$feed_url"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0); # GRAB THE XML FILE. $xmlX = curl_exec($curl); curl_close($curl); # SET UP XML OBJECT. # Use either one of these, depending on revision of PHP. # Comment-out the line you are not using. //$xml = new SimpleXMLElement($xmlX); $xml = simplexml_load_string($xmlX); foreach($xml->Players as $item){ echo " Name: {$item->Player->Name}<br /> Aircraft: {$item->Player->Aircraft}<br /> <br /> "; } foreach($xml->FlightPlans as $item){ echo " Name: {$item->FlightPlan->PlayerName}<br /> Plan: {$item->FlightPlan->Plan}<br /> <br /> "; } ?> EDIT: here is the page http://linkvirtual.getfreehosting.co.uk/fshost/aircraft.php Cheers. Quote
Administrators Nabeel Posted August 13, 2009 Administrators Report Posted August 13, 2009 This works: $xml = simplexml_load_string($xmlX); foreach($xml->Players->Player as $player) { echo $player->Name .'<br />'; } You want to cycle through each "Player", since there are multiple sections of that, not just one player. Sorry took so long! Quote
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.