Skip to content

Instantly share code, notes, and snippets.

@TheFox
Last active February 12, 2017 16:10
Show Gist options
  • Save TheFox/6201905 to your computer and use it in GitHub Desktop.
Save TheFox/6201905 to your computer and use it in GitHub Desktop.
<?php
function sibyte($byte){
$e = array('B', 'K', 'M', 'G');
$n = 0;
while($byte >= 1024 && $n < 10){
$n++;
$byte = $byte / 1024;
}
$sbyte = ''.$byte;
if(strpos($sbyte, '.') !== false){
$sbyte = substr($sbyte, 0, strpos($sbyte, '.') + 2);
}
if(substr($sbyte, strpos($sbyte, '.') + 1) == '.0'){
$sbyte = substr($sbyte, 0, strpos($sbyte, '.'));
}
return $sbyte.$e[$n + 1].$e[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment