From dd5ef9cdd0dd965e990ba42f584fbf9af2bba127 Mon Sep 17 00:00:00 2001 From: Volker Dusch Date: Wed, 8 Jan 2025 15:17:50 +0100 Subject: [PATCH] ini_get: Update example to use `ini_parse_quantity()` Resolves php/doc-en#4185 --- reference/info/functions/ini-get.xml | 37 ++++--------------- .../info/functions/ini-parse-quantity.xml | 2 +- 2 files changed, 9 insertions(+), 30 deletions(-) diff --git a/reference/info/functions/ini-get.xml b/reference/info/functions/ini-get.xml index b14ac98f5abf..5f8163c87946 100644 --- a/reference/info/functions/ini-get.xml +++ b/reference/info/functions/ini-get.xml @@ -55,37 +55,15 @@ Our php.ini contains the following settings: display_errors = On -register_globals = Off +opcache.enable_cli = Off post_max_size = 8M */ echo 'display_errors = ' . ini_get('display_errors') . "\n"; -echo 'register_globals = ' . (int) ini_get('register_globals') . "\n"; +echo 'opcache.enable_cli = ' . (int) ini_get('opcache.enable_cli') . "\n"; echo 'post_max_size = ' . ini_get('post_max_size') . "\n"; echo 'post_max_size + 1 = ' . (rtrim(ini_get('post_max_size'), 'KMG') + 1) . "\n"; -echo 'post_max_size in bytes = ' . return_bytes(ini_get('post_max_size')); - -function return_bytes($val) -{ - $val = trim($val); - $num = (int) rtrim($val, 'KMG'); - $last = strtolower($val[strlen($val) - 1]); - - switch ($last) { - // The 'G' modifier is available - case 'g': - $num = $num * 1024 * 1024 * 1024; - break; - case 'm': - $num = $num * 1024 * 1024; - break; - case 'k': - $num *= 1024; - break; - } - - return $num; -} +echo 'post_max_size in bytes = ' . ini_parse_quantity(ini_get('post_max_size')); ?> ]]> @@ -95,7 +73,7 @@ function return_bytes($val) ini_get will return the exact string stored in the &php.ini; file and NOT its int equivalent. Attempting normal arithmetic functions on these values - will not have otherwise expected results. The example above shows one - way to convert shorthand notation into bytes, much like how the PHP - source does it. + will not have otherwise expected results. The + ini_parse_quantity function can be used to convert + the shorthand notation into bytes. @@ -145,6 +123,7 @@ post_max_size in bytes = 8388608 get_cfg_var ini_get_all + ini_parse_quantity ini_restore ini_set diff --git a/reference/info/functions/ini-parse-quantity.xml b/reference/info/functions/ini-parse-quantity.xml index c0357c86a817..fa4e018161f3 100644 --- a/reference/info/functions/ini-parse-quantity.xml +++ b/reference/info/functions/ini-parse-quantity.xml @@ -77,7 +77,7 @@ var_dump(ini_parse_quantity('10F')); ?> ]]> - &example.outputs.similar; + &example.outputs;