Your webservice (URL: http://api.minetools.eu/ping/play.desnia.net/25565) returns JSON.
This is a standard format, and PHP (at least since 5.2) supports decoding it natively - you'll get some form of PHP structure back from it.
Your code currently doesn't work (your syntax is meaningless on the echo - and even if it was valid, you're treating a string copy of the raw JSON data as an array - which won't work), you need to have PHP interpret (decode) the JSON data first:
http://php.net/manual/en/function.json-decode.php
<?php
$statisticsJson = file_get_contents("http://api.minetools.eu/ping/play.desnia.net/25565");
$statisticsObj = json_decode($statisticsJson);
Your $statisticsObj will be NULL if an error occurred - and you can get that error using other standard PHP functions:
http://php.net/manual/en/function.json-last-error.php
Assuming it isn't NULL, you can examine the structure of the object with var_dump($statisticsObj) - and then alter your code to print it out appropriately.
In short, something like:
<?php
$statisticsJson = file_get_contents("http://api.minetools.eu/ping/play.desnia.net/25565");
$statisticsObj = json_decode($statisticsJson);
if ($statisticsObj !== null) {
echo $statisticsObj->players->online;
} else {
echo "Unknown";
}
You should also check what comes back from file_get_contents() too - various return values can come back (which would blow up json_decode()) on errors. See the documentation for possibilities:
http://php.net/manual/en/function.file-get-contents.php
I'd also wrap the entire thing in a function or class method to keep your code tidy. A simple "almost complete" solution could look like this:
<?php
function getServerStatistics($url) {
$statisticsJson = file_get_contents($url);
if ($statisticsJson === false) {
return false;
}
$statisticsObj = json_decode($statisticsJson);
if ($statisticsObj !== null) {
return false;
}
return $statisticsObj;
}
// ...
$stats = getServerStatistics($url);
if ($stats !== false) {
print $stats->players->online;
}
If you want better handling over server / HTTP errors etc, I'd look at using curl_*() - http://php.net/manual/en/book.curl.php
Ideally you also should be confirming the structure returned from your webservice is what you expected before blindly making assumptions too. You can do that with something like property_exists().
Happy hacking!