Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.
parsebytesize
This function will convert bytes into kb, mb, gb or tb depending on the $size. How many digits displayed is given by $digits.

parsebytesize

Quote

parsebytesize ( int $size [, int $digits [, bol $dir ] ] )


Parameters
size
The size you want to parse

digits
It's a bit wrong name, this is the number of decimal digits at the end

dir
Set this to true if you want the function to return empty if the size is 0, default is true

Return Values
This function will return the easiest way to display the size of bytes

Examples

Example 1
Code
<?php
echo parsebytesize(100);
echo parsebytesize(10000, 3);
echo parsebytesize(1000000, 4);
echo parsebytesize(100000000);
?>

Here we will parse different sizes of bytes to get the best and simplest way to display them

Output to Example 1

Quote

100Bytes
9.766Kb
976.562Kb
95.37Mb


Example 2
Code
<?php
parsebytesize(0);
parsebytesize(0, 2, true);
?>
Here we will try out to have the parsebytesize() function with an empty size. You see if we set the $dir variable to true, the function will return empty in stead of 0 bytes

Output to Example 2

Quote

0Bytes
Empty


Changelog
7.01.02 - Output text is now using locales.
7.01.00 - Fixed bits to bytes for correct ISO standards.


See also …


References