array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.ini-parse-quantity.php', 1 => 'ini_parse_quantity', ), 'up' => array ( 0 => 'ref.info.php', 1 => 'PHP 选项/信息 函数', ), 'prev' => array ( 0 => 'function.ini-get.php', 1 => 'ini_get', ), 'next' => array ( 0 => 'function.ini-restore.php', 1 => 'ini_restore', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/info/functions/ini-parse-quantity.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 8 >= 8.2.0)
ini_parse_quantity — Get interpreted size from ini shorthand syntax
Returns the interpreted size in bytes on success from an ini shorthand.
shorthand
Ini shorthand to parse, must be a number followed by an optional multiplier.
The following multipliers are supported: k
/K
(1024
),
m
/M
(1048576
),
g
/G
(1073741824
).
The number can be a decimal, hex (prefixed with 0x
or 0X
),
octal (prefixed with 0o
, 0O
or 0
) or binary (prefixed with
0b
or 0B
)
Returns the interpreted size in bytes as an int.
If the value cannot be parsed, or an invalid multiplier is used, an E_WARNING
is raised.
示例 #1 A few ini_parse_quantity() examples
<?php
var_dump(ini_parse_quantity('1024'));
var_dump(ini_parse_quantity('1024M'));
var_dump(ini_parse_quantity('512K'));
var_dump(ini_parse_quantity('0xFFk'));
var_dump(ini_parse_quantity('0b1010k'));
var_dump(ini_parse_quantity('0o1024'));
var_dump(ini_parse_quantity('01024'));
var_dump(ini_parse_quantity('Foobar'));
var_dump(ini_parse_quantity('10F'));
?>
以上示例的输出类似于:
int(1024) int(1073741824) int(524288) int(261120) int(10240) int(532) int(532) Warning: Invalid quantity "Foobar": no valid leading digits, interpreting as "0" for backwards compatibility int(0) Warning: Invalid quantity "10F": unknown multiplier "F", interpreting as "10" for backwards compatibility int(10)