3v4l.org

run code in 200+ PHP versions simultaneously
<?php /** * convertBytes * * Convert bytes into human readable form with rounding * * @name convertBytes * @access public * @param integer $bytes * @param integer $decimals = 2 * @desc Convert bytes into human readable form with rounding * @return string */ function convertBytes($bytes, $decimals = 2) { $suffixes = 'BKMGTP'; $factor = floor((strlen($bytes) - 1) / 3); return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$suffixes[$factor]; } echo PHP_INT_SIZE . "\n"; echo convertBytes(1500)."\n"; echo convertBytes(1500*1000)."\n"; echo convertBytes(1500*1000*1000)."\n"; echo convertBytes(1500*1000*1000*1000)."\n"; echo convertBytes(1500*1000*1000*1000*1000)."\n";
Output for 4.4.0 - 4.4.9, 5.0.5 - 7.3.5
8 1.46K 1.43M 1.40G 1.36T 1.33P
Output for 4.3.0 - 4.3.11, 5.0.0 - 5.0.4
Notice: Use of undefined constant PHP_INT_SIZE - assumed 'PHP_INT_SIZE' in /in/rCeaP on line 22 PHP_INT_SIZE 1.46K 1.43M 1.40G 1.36T 1.33P