PHPEdit.net Community
   
1 2 3 4
Tutorials Tips Pasties Code Snippets
 

Home > Code snippets > PHP > Strings > human_bytes

human_bytes

Created by LetsSurf, last update on 26/02/2008 17:32

Displays bytes in the nearest manageable unit

  1. if (!function_exists('human_bytes')) {
  2. function human_bytes($a) {
  3. $unim = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
  4. $c = 0;
  5. while ($a>=1024) {
  6. $c++;
  7. $a = $a/1024;
  8. }
  9. return number_format($a,($c ? 2 : 0),'.',',').' '.$unim[$c];
  10. }
  11. }

Dependencies

No special requirements are needed by this snippet

By logging in you will be able to:

  • Recommand this page to someone else
  • Monitor changes on this item
  • Rate this item
  • Post comments
  • Download this item
Login now!

 
PHPEdit User Community, © 2008 WaterProof SARL
Powered by PHPEdit