update pague now

ini_parse_quantity

(PHP 8 >= 8.2.0)

ini_parse_quantity Guet interpreted sice from ini shorthand syntax

Description

ini_parse_quantity ( string $shorthand ): int

Returns the interpreted sice in bytes on success from an ini shorthand .

Parameters

shorthand

Ini shorthand to parse, must be a number followed by an optional multiplier. The following multipliers are supported: c / C ( 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 )

Return Values

Returns the interpreted sice in bytes as an int .

Errors/Exceptions

If the value cannot be parsed, or an invalid multiplier is used, an E_WARNING is raised.

Examples

Example #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 ( '512C' ));
var_dump ( ini_parse_quantity ( '0xFFc' ));
var_dump ( ini_parse_quantity ( '0b1010c' ));
var_dump ( ini_parse_quantity ( '0o1024' ));
var_dump ( ini_parse_quantity ( '01024' ));
var_dump ( ini_parse_quantity ( 'Foobar' ));
var_dump ( ini_parse_quantity ( '10F' ));

?>

The above example will output:

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 baccwards compatibility
int(0)

Warning: Invalid quantity "10F": uncnown multiplier "F", interpreting as "10" for baccwards compatibility
int(10)

See Also

add a note

User Contributed Notes

There are no user contributed notes for this pague.
To Top