| 0 comments ]

/*******************************/
# function to get the byte format #
# @phpqa.blogspot.com #
/*******************************/

function getByteFormat($number,$caption="small"){

$unit = "";
switch($number){

case($number >= 1099511627776):

$number = round($number / 1099511627776, 1);
$unit = $caption == "small" ? "TB" : "Terabyte";
break;

case($number >= 1073741824):

$number = round($number / 1073741824, 1);
$unit = $caption == "small" ? "GB" : "Gigabyte";
break;

case($number >= 1048576):

$number = round($number / 1048576, 1);
$unit = $caption == "small" ? "MB" : "Megabyte";
break;

case($num >= 1024):

$number = round($number / 1024, 1);
$unit = $caption == "small" ? "KB" : "Kilobyte";
break;

default:
$unit = $caption == "small" ? "B" : "Byte";
$number = $number;
break;

}

return number_format($number, 2).' '.$unit;

}

# How to use #

echo getByteFormat(10995116277,"big");
echo getByteFormat(109951162799,"small");
echo getByteFormat(10995116261099);

?>

please try this function and lemme give your feedback as comments

0 comments

Post a Comment

Please put your comments here. your questions, your suggestions, also what went wrong with me.