We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

tylerhall on 12/31/69


Tagged

scott textmate bytesize math human readable


Versions (?)


Who likes this?

16 people have marked this snippet as a favorite

bomberstudios
daniel
Roshambo
neverwolf
ndegruchy
irdial
vaaaska
blakeb
fael
marteki
chucktrukk
Firemarble
mb
Keef
nicogranelli
JimiJay


Make bytesizes human readable


Published in: PHP 


  1. function human_readable($val, $round = 0)
  2. {
  3. $unit = array('','K','M','G','T','P','E','Z','Y');
  4. while($val >= 1000)
  5. {
  6. $val /= 1024;
  7. array_shift($unit);
  8. }
  9. return round($val, $round) . array_shift($unit) . "B";
  10. }

Report this snippet 

You need to login to post a comment.