Jump to content

Off Topic - PHP Help


G-NEWC

Recommended Posts

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.

Link to comment
Share on other sites

  • Administrators

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!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...