3v4l.org

run code in 500+ PHP versions simultaneously
<?php function bytes_to_int($size) { var_dump($size); // Remove the non-unit characters from the size. $unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-numeric characters from the size. $size = preg_replace('/[^0-9\.]/', '', $size); if ($unit) { var_dump(round($size * pow(1024, stripos('bkmgtpezy', $unit[0])))); } else { var_dump(round((float) $size)); } print "\n\n"; } bytes_to_int('12,2'); bytes_to_int('12,2 b'); bytes_to_int(''); bytes_to_int('m');
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.21, 8.5.0 - 8.5.7
string(4) "12,2" float(122) string(6) "12,2 b" float(122) string(0) "" float(0) string(1) "m" Fatal error: Uncaught TypeError: Unsupported operand types: string * int in /in/F83lJ:11 Stack trace: #0 /in/F83lJ(22): bytes_to_int('') #1 {main} thrown in /in/F83lJ on line 11
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
string(4) "12,2" float(122) string(6) "12,2 b" float(122) string(0) "" float(0) string(1) "m" Warning: A non-numeric value encountered in /in/F83lJ on line 11 float(0)

preferences:
77.99 ms | 1552 KiB | 4 Q