3v4l.org

run code in 300+ PHP versions simultaneously
<?php function normalizeIniBytes($val) { $val = trim($val); $last = strtolower(substr($val, -1, 1)); if (ord($last) < 0x30 || ord($last) > 0x39) { $bytes = substr($val, 0, -1); switch ($last) { case 'g': $bytes *= 1024; // fall through case 'm': $bytes *= 1024; // fall through case 'k': $bytes *= 1024; break; } } else { $bytes = $val; } if ($bytes >= (1 << 30)) { return ($bytes >> 30) . 'GB'; } elseif ($bytes >= (1 << 20)) { return ($bytes >> 20) . 'MB'; } elseif ($bytes >= (1 << 10)) { return ($bytes >> 10) . 'KB'; } return $bytes . 'B'; } echo normalizeIniBytes("1") . "\n"; echo normalizeIniBytes("10") . "\n"; echo normalizeIniBytes("1024") . "\n"; echo normalizeIniBytes("1K") . "\n"; echo normalizeIniBytes("1048576") . "\n"; echo normalizeIniBytes("1024K") . "\n"; echo normalizeIniBytes("1M") . "\n"; echo normalizeIniBytes("1023M") . "\n"; echo normalizeIniBytes("1G") . "\n";
Output for 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.19, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
1B 10B 1KB 1KB 1MB 1MB 1MB 1023MB 1GB
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 1B 10B 1KB 1KB 1MB 1MB 1MB 1023MB 1GB

preferences:
210.33 ms | 402 KiB | 181 Q