Answers for "external api php"

PHP
0

external api php

<?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;
}
Posted by: Guest on March-04-2021

Browse Popular Code Answers by Language