note 25435 deleted from function.filesize by tomsommer
| From: | tomsommer@php.net | Date: | Wed, 01 Sep 2004 17:33:45 +0000 |
| Subject: | note 25435 deleted from function.filesize by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-75884@lists.php.net to get a copy of this message | ||
Note Submitter: cnww at a host called k-pcltee dot com
----
A nice short human readable function:
function human_readable( $number, $base=1024,
$suffixes=array( " B", " KB", " MB", " GB", "
TB", " PB", " EB" )
)
{
$usesuf = 0;
$n = (float) $number; //Appears to be necessary to avoid rounding
while( $n >= $base ) {
$n /= (float) $base;
$usesuf++;
}
$places = 2 - floor( log10( $n ) );
$places = max( $places, 0 );
$retval = number_format( $n, $places, ".", "" ) . $suffixes[$usesuf];
return $retval;
}