<?php function convertToBytes(string $memoryLimit): int { $memoryLimit = strtolower($memoryLimit); $max = ltrim($memoryLimit, '+'); if (str_starts_with($max, '0x')) { $max = \intval($max, 16); } elseif (str_starts_with($max, '0')) { $max = \intval($max, 8); } else { $max = (int) $max; } switch (substr(rtrim($memoryLimit, 'b'), -1)) { case 't': $max *= 1024; // no break case 'g': $max *= 1024; // no break case 'm': $max *= 1024; // no break case 'k': $max *= 1024; } return $max; } var_dump(convertToBytes('1G')); var_dump(convertToBytes('1.5G'));
You have javascript disabled. You will not be able to edit any code.