3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function fb1($bytes, $precision = 2) { $units = array('B', 'KB', 'MB', 'GB', 'TB'); $bytes = max($bytes, 0); $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); $pow = min($pow, count($units) - 1); // Uncomment one of the following alternatives // $bytes /= pow(1024, $pow); // $bytes /= (1 << (10 * $pow)); return round($bytes, $precision) . ' ' . $units[$pow]; } function fb2($size, $precision = 2) { $base = log($size) / log(1024); $suffixes = array('', 'k', 'M', 'G', 'T'); return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)]; } function fb3($size) { $base = log($size) / log(1024); $suffix = array("", "k", "M", "G", "T")[floor($base)]; return pow(1024, $base - floor($base)) . $suffix; } echo fb1(24962496) . "\n\n"; echo fb2(24962496) . "\n\n"; echo fb3(24962496) . "\n\n";
Output for 5.5.24 - 7.1.0
24962496 MB 23.81M 23.806091308594M
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.4.45
Parse error: syntax error, unexpected '[' in /in/S2Go0 on line 28
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/S2Go0 on line 28
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/S2Go0 on line 28
Process exited with code 255.