note 88271 modified in function.filesize by danbrown

From: Date: Sun, 18 Jan 2009 17:31:56 +0000
Subject: note 88271 modified in function.filesize by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-149392@lists.php.net to get a copy of this message
Hi, this is my very fast version of byteConvert(). Without using costly pow() function. <?php /** * Byte converting with formated number * * @param int $bytes bytes * @return string */ function byteConvert(&$bytes){ $b = (int)$bytes; $s = array('B', 'kB', 'MB', 'GB', 'TB'); if($b < 0){ return "0 ".$s[0]; } $con = 1024; $e = (int)(log($b,$con)); return number_format($b/pow($con,$e),2,',','.').' '.$s[$e]; ?> --was-- @Bug in my post from 08-Jan-2009 12:46 Hi guys, there is a bug in my post. Please use only this version <?php /** * Byte converting with formated number * * @param int $bytes bytes * @return string */ function byteConvert(&$bytes){ $b = (int)$bytes; $s = array('B', 'kB', 'MB', 'GB', 'TB'); if($b < 0){ return "0 ".$s[0]; } $con = 1024; $e = (int)(log($b,$con)); return number_format($b/pow($con,$e),2,',','.').' '.$s[$e]; ?> http://php.net/manual/en/function.filesize.php

« previous php.notes (#149392) next »