Skip to content

Commit b7f3ae5

Browse files
committed
IHF: Format helpers added.
1 parent 75eed99 commit b7f3ae5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/format.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
if (!function_exists('format_bytes')) {
4+
function format_bytes($bytes, $precision = 2)
5+
{
6+
$units = ['B', 'kB', 'MB', 'GB', 'TB'];
7+
8+
$maxFactor = count($units) - 1;
9+
$factor = floor(((strlen($bytes) - 1) / 3));
10+
$factor = ($factor > $maxFactor) ? $maxFactor : $factor;
11+
12+
return sprintf("%.{$precision}f", ($bytes / pow(1024, $factor))) . $units[$factor];
13+
}
14+
}

0 commit comments

Comments
 (0)