Humanize bytes view helper
1 2 3 4 56 7 8 9 1011 12 13 14 1516 | class Zend_View_Helper_Humanize { public function humanize($bytes) { $orig = $bytes; $ext = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); $unitCount = 0; for(; $bytes > 1024; $unitCount++) $bytes /= 1024; $human1 = sprintf("%s %s", round($bytes, 2), $ext[$unitCount]); $human2 = sprintf("%s %s", $orig, $ext[0]); return $human1 == $human2 ? $human1 : sprintf("%s (%s)", $human1, $human2); }} |
Comments
You must login before commenting on a snippet. If you do not have an account, please register.
1 year ago
Nice work. There is Zend_Measure_Binary as well ;)