3v4l.org

run code in 300+ 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, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.28, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
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

preferences:
321.83 ms | 402 KiB | 433 Q