This is my suggestion which should be future-proof (with regard to PHP Versions 7++)!
function return_bytes($val, $gotISO = false) {
// This is my ultimate "return_bytes" function!
// Converts (not only) the PHP shorthand notation which is returned by e.g. "ini_get()"
// Special features:
// Doesn't need regular expression and switch-case conditionals.
// Identifies beside "Kilo", "Mega" and "Giga" also "Tera", "Peta", "Exa", "Zetta", and "Yotta" too!
// Ignores spaces and doesn't make no difference between e.g. "M" or "MB"!
// By default possible commas (,) as thousand separator will be erased. Example: "1,000.00" will "be 1000.00".
// If ($gotISO == true) it converts ISO formatted values like "1.000,00" into "1000.00".
$pwr = 0;
if(empty($val)) return 0;
$val = trim($val);
if (is_numeric($val)) return $val;
if ($gotISO) {
$val = str_replace('.','',$val); // wipe possibe thousend separators (.)
$val = str_replace(',','.',$val); // convert ISO comma to value point
} else {
$val = str_replace(',','',$val); // wipe possibe thousend separators (,)
}
$val = str_replace(' ','',$val);
if (floatval($val) == 0) return 0;
if (stripos($val, 'k') !== false) $pwr = 1;
elseif (stripos($val, 'm') !== false) $pwr = 2;
elseif (stripos($val, 'g') !== false) $pwr = 3;
elseif (stripos($val, 't') !== false) $pwr = 4;
elseif (stripos($val, 'p') !== false) $pwr = 5;
elseif (stripos($val, 'e') !== false) $pwr = 6;
elseif (stripos($val, 'z') !== false) $pwr = 7;
elseif (stripos($val, 'y') !== false) $pwr = 8;
$val *= pow(1024, $pwr);
return $val;
}
... have fun with it!