samedi 16 mai 2020

PHP If else inside function outputting NaN

Having some trouble trying to get the output of this to display "offline" when it is offline..The count function performs as intended, but as soon as I take the file offline, I just get NaN as the output instead of "offline". I noticed when changing the line echo 'offline';to an integer it displays fine.

<?
    function getPlexXML($url)
    {
    libxml_use_internal_errors(true);
    $xml = simplexml_load_file($url);
    $count = number_format((float)$xml['totalSize']);

    if (false === $xml) {
        echo 'offline';
    } else {
        echo $count;
    }
    }


getPlexXML('https://xxx.example.com/library/sections/1/all?type=1&X-Plex-Container-Start=0&X-Plex-Container-Size=0&X-Plex-Token=xxxxxxx');
?>

Update: There is some javascript that counts up the number of the variable displayed. Any way to still use this, but have it not activate when the function does not pull an integer?

<script>
// Media counter script
$('.counter').each(function() {
    $(this).prop('Counter', 0).animate({
        Counter: parseFloat($(this).text().replace(/,/g, ''))
    }, {
        duration: 2000,
        easing: 'swing',
        step: function(now) {
            $(this).text(getRupeesFormat(Math.ceil(now)));
        }
    });
});


function getRupeesFormat(val) {
    while (/(\d+)(\d{3})/.test(val.toString())) {
        val = val.toString().replace(/(\d+)(\d{3})/, '$1' + ',' + '$2');
    }
    return val;
}
</script>

Aucun commentaire:

Enregistrer un commentaire