Am urmatorul script :
Cod: Selectaţi tot
if(($json = @file_get_contents("http://api.ets2mp.com/servers/")) !== FALSE) {//Schaut ob die Datei online/Verfügbar ist.
$json = json_decode($json, TRUE);//String wird Dekodiert
if(json_last_error() == JSON_ERROR_NONE) {//Schaut ob Fehler drine sind, die nicht gelesen werden können.
foreach($json['response'] as $server) {//Eine kleine schrleife
if($server['online'] == 1) {//Server Status abfrage, Online.
echo ''.$server['name'].': Server Online, Spieler Online: '.$server['players'].'
'; //Text ausgabe
}else if($server['online'] == 0) {//Server Status abfrage, Offline.
echo $server['name'].': Server Offline
';//Text ausgabe
}
}
}
}
Cod: Selectaţi tot
http://api.ets2mp.com/servers/
Cod: Selectaţi tot
{"error":"false","response":[{"id":1,"ip":"37.187.170.151","port":42860,"name":"Europe #1","shortname":"EU #1","online":true,"players":2084,"maxplayers":3500,"speedlimiter":1},{"id":3,"ip":"191.101.3.39","port":42860,"name":"United states #1","shortname":"US #1","online":true,"players":25,"maxplayers":500,"speedlimiter":1},{"id":4,"ip":"151.80.47.35","port":42880,"name":"Europe #2","shortname":"EU #2","online":true,"players":569,"maxplayers":2300,"speedlimiter":0},{"id":6,"ip":"1.asia.game.kat.pw","port":42860,"name":"Asia #1","shortname":"AS #1","online":true,"players":33,"maxplayers":500,"speedlimiter":1},{"id":7,"ip":"1.brazil.game.kat.pw","port":42860,"name":"South America #1","shortname":"SA #1","online":true,"players":18,"maxplayers":750,"speedlimiter":1},{"id":9,"ip":"139.162.29.242","port":42860,"name":"Asia #1 (Relay)","shortname":"AS[R] #1","online":true,"players":33,"maxplayers":500,"speedlimiter":1}]}