Question: I have the URL <http://api.minetools.eu/ping/play.desnia.net/25565> which outputs statistics of my server.

For example:

```
{
  "description": "A Minecraft Server",
  "favicon": null,
  "latency": 64.646,
  "players": {
    "max": 20,
    "online": 0,
    "sample": []
  },
  "version": {
    "name": "Spigot 1.8.8",
    "protocol": 47
  }
}

```

I want to get the value of online player count to display it on my website as: Online Players: online amount

Can anyone help?

I tried to do: 

```
<b> Online players: 

<?php
$content = file_get_contents("http://api.minetools.eu/ping/play.desnia.net/25565");
echo ($content, ["online"]);
}
?>
</b>

```

But it didn't work.

Answer: 
**1) Don't use [`file_get_contents()`](http://php.net/file_get_contents)** (If you can help it)

This is because you'd need to [enable `fopen_wrappers`](http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen) to enable [`file_get_contents()`](http://php.net/file_get_contents) to work on an external source. Sometimes this is closed (depending on your host; like shared hosting), so your application will break.

Generally a good alternative is [`curl()`](http://php.net/curl)

**2) Using [`curl()`](http://php.net/curl) to perform a `GET` request**

This is pretty straight forward. Issue a `GET` request with some headers using [`curl()`](http://php.net/curl).

```
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "http://api.minetools.eu/ping/play.desnia.net/25565",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

```

**3) Using the response**

The response comes back in a [JSON object](http://www.json.org/). We can use [`json_decode()`](http://php.net/json_decode) to put this into a usable object or array.

```
$response = json_decode($response, true); //because of true, it's in an array
echo 'Online: '. $response['players']['online'];

```
Your server is returning a JSON string.
So you should use **json\_decode()** function to convert that into a plain PHP object.
Thereafter you can access any variable of that object.

So, something like this shall help

```
<?php
$content =     file_get_contents("http://api.minetools.eu/ping/play.desnia.net/25565");

$result  = json_decode($content);

print_r( $result->players->online );
?>

```

More details for json\_decode can be read here -
<http://php.net/manual/en/function.json-decode.php>