[Printable]
Share

bytes_readable

Posted: Sun 11th December 2005 in Scripts

Simple PHP fucntion that turns a number in octets (normal 8 bit bytes) into a human readable number for convenient display.

  Works well with the numbers from a radius accounting table, originally written for piertopier.net

USAGE
just go:
bytes_readable(number);

 

// simple function to convert bytes to readable a readable format
// tom 2005
function bytes_readable($bytes)
{         switch ($bytes) {
          case ($bytes < 1024):
               $read_bytes=$bytes; $abv='b';
          break;
          case ($bytes < 1048576):
               $read_bytes=round ($bytes/1024); $abv='k';
          break;
          case ($bytes < 1073741824):
               $read_bytes=round($bytes/1048576); $abv='M';
          break;
          case ($bytes > 1073741824):
               $read_bytes=round ($bytes/1073741824); $abv='g';
          break; 
          }
    return ($read_bytes.$abv);
}
?>
[Printable]
Share

bytes_readable

Posted: Sun 11th December 2005 in Scripts

bytes_readable

Simple PHP fucntion that turns a number in octets (normal 8 bit bytes) into a human readable number for convenient display.

  Works well with the numbers from a radius accounting table, originally written for piertopier.net

USAGE
just go:
bytes_readable(number);

 

// simple function to convert bytes to readable a readable format
// tom 2005
function bytes_readable($bytes)
{         switch ($bytes) {
          case ($bytes < 1024):
               $read_bytes=$bytes; $abv='b';
          break;
          case ($bytes < 1048576):
               $read_bytes=round ($bytes/1024); $abv='k';
          break;
          case ($bytes < 1073741824):
               $read_bytes=round($bytes/1048576); $abv='M';
          break;
          case ($bytes > 1073741824):
               $read_bytes=round ($bytes/1073741824); $abv='g';
          break; 
          }
    return ($read_bytes.$abv);
}
?>