The paragraph you linked to结束:
You may not use these shorthand notations outside of PHP.ini,instead
use an integer value of bytes. See 07001 for an
example on how to convert these values.
这会导致你这样的东西(我稍稍修改):
function return_bytes($val)
{
$val = trim($val);
$last = strtolower($val[strlen($val)-1]);
$val = substr($val,-1); // necessary since PHP 7.1; otherwise optional
switch($last) {
// The 'G' modifier is available since PHP 5.1.0
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}
return $val;
}
echo return_bytes("3M");
// Output: 3145728
没有内置函数执行此任务;回想一下,真正的INI设置是在PHP内部设计的. PHP源使用与上述类似的功能.