Jump to content

Archived

This topic is now archived and is closed to further replies.

DmdFreak

Help parsing this info

Recommended Posts

I'm trying to do a file_get_contents() on the following URL then parse the info.
http://game.trackmanianations.com/online_game/www_serverslist.php
I want to end up with the server name and each of the players that are on at that moment.
I want to then turn around and post this info as live results on my website.

[code]- <server>
  <host>freaksserver2</host>
- <players>
  <player>Fredrik_Smart</player>
  <player>Susie2002</player>
  <player>_milllan_</player>
  <player>BALTAZAR_</player>
  <player>ZiLWooD</player>
  <player>Mr._Flips</player>
  <player>Ayzblokk</player>
  <player>Rose_Tattoo</player>
  </players>
  </server>[/code]

When I do the file_get_content() I end up with only the names, but when I insert the same URL straight into the browser, I get a coded active page. If anyone has any idea of another way of getting what I want out of this page it would be great. I'm very new to PHP.

Thanks!

Share this post


Link to post
Share on other sites
Does this help

[code]
<?php
$xml = simplexml_load_file('http://game.trackmanianations.com/online_game/www_serverslist.php');

foreach ($xml as $server) {
    echo "<h3> ------ $server->host ------ </h3>";
    foreach ($server->players as $playerlist) {
        if ($playerlist->player)
            foreach ($playerlist->player as $name) {
                echo $name . '<br/>';
            }
        else echo 'No players<br/>';
    }
}
?>
[/code]

Share this post


Link to post
Share on other sites
Totally helped! Thanks a bunch! I can edit it from here to list just the servers I want to list. Many many thanks!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.