string bytes2human(int bytes [, int precision]) -- Convert a number of bytes to human readable.
<?php |
This will output:
125926 is 122.97kB |
Published under the terms of the BSD License
<?php
function bytes2human($bytes, $precision = 2) {
if (abs($bytes)<1024) return $bytes."B";
$suffixes = array("kB","MB","GB","TB","PB","EB","ZB","YB");
for($i=0,$bytes /= 1024;abs($bytes)>1024;$i++, $bytes /= 1024);
return sprintf("%01.${precision}f ", $bytes).$suffixes[$i];
}
?>
Last updated: Sat Jun 14 20:02:45 CEST 2008