Format bytes with PHP – B, KB, MB, GB, TB, PB, EB, ZB, YB converter - Comment Page: 2
Simple PHP function that formats the bytes to the desired form. Possible unit options are:
Byte (B)
Kilobyte (KB)
Megabyte (MB)
Gigabyte (GB)
Terabyte (TB)
Petabyte (PB)
Exabyte (EB)
Zettabyte (ZB)
Yottabyte (YB)
Function takes three parameter: (bytes mandatory, unit optional, decimals optional)
[inttf_post_ad1]
PHP byteFormat function for formatting bytes
<?php
function byteFormat($bytes, $unit = "", $decimals = 2) {
$units = array('B' => 0, 'KB' => 1, 'MB' => 2, 'GB' => 3, 'TB' => 4,
'PB' => 5, 'EB' => 6, 'ZB' => 7, 'YB' => 8);
$value = 0;
if ($bytes > 0) {
// Generate automatic prefix by bytes
// If wrong prefix...
Thank to help me
After yb bronto byte and Geo bytes are there, please add those too
Hi Ali,
Thanks, I’m not sure are Bronto and Geop official names, but yes you can easily add both using their abbreviations BB and GPB.
This is a good website because I never heard of Petabytes, Exabytes, Zettabytes and Yottabytes.
You forgot Geobytes and Brontobytes. Please add them in.
Hi Fern,
Check my answer to Ali. Bronto and Geop are not officially accepted names, but you can use both on your own code if you want.
good.This website is usefull for me.Thank you