0

I need to get the JSON data from here https://use.gameapis.net/mc/query/info/play.mineverge.net

I need the "online": 126 to display in my web page.

"players": {
    "online": 126,
    "max": 500

here is my current code that (not working) to get the JSON. Am I doing something wrong? It displays everything not just "online":

             $playeronline = file_get_contents ('https://use.gameapis.net/mc/query/info/' . $server); 
            echo $playeronline->players[1]; 
            echo $playeronline['online']; 
Nydigov
  • 15
  • 4

3 Answers3

1

try this ,

$playeronline = file_get_contents ('https://use.gameapis.net/mc/query/info/' . $server); 
$data=json_decode($playeronline,true);

echo $data['players']['online']; 
1

This worked for me, and I tested it:

$str = file_get_contents ('https://use.gameapis.net/mc/query/info/play.mineverge.net');

$playersonline = json_decode( $str );

echo $playersonline->players->online;
Brian Gottier
  • 4,522
  • 3
  • 21
  • 37
0

As stated here you need to use the json_decode function as follows:

$playeronline = file_get_contents('https://use.gameapis.net/mc/query/info/' . $server); 

$obj = json_decode($playeronline );
echo $playersonline->players->online;
Purple Haze
  • 530
  • 7
  • 22