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...

20 comments on “Format bytes with PHP – B, KB, MB, GB, TB, PB, EB, ZB, YB converter - Comment Page: 2

1 2
    1. Thank to help me

      Reply
    2. After yb bronto byte and Geo bytes are there, please add those too

      Reply
      • 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.

        Reply
1 2

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close