Skip to content

Commit 4c016ab

Browse files
authored
ini_get: Update example to use ini_parse_quantity() (#4372)
Resolves #4185
1 parent c7e83fb commit 4c016ab

File tree

2 files changed

+9
-30
lines changed

2 files changed

+9
-30
lines changed

reference/info/functions/ini-get.xml

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -55,37 +55,15 @@
5555
Our php.ini contains the following settings:
5656
5757
display_errors = On
58-
register_globals = Off
58+
opcache.enable_cli = Off
5959
post_max_size = 8M
6060
*/
6161
6262
echo 'display_errors = ' . ini_get('display_errors') . "\n";
63-
echo 'register_globals = ' . (int) ini_get('register_globals') . "\n";
63+
echo 'opcache.enable_cli = ' . (int) ini_get('opcache.enable_cli') . "\n";
6464
echo 'post_max_size = ' . ini_get('post_max_size') . "\n";
6565
echo 'post_max_size + 1 = ' . (rtrim(ini_get('post_max_size'), 'KMG') + 1) . "\n";
66-
echo 'post_max_size in bytes = ' . return_bytes(ini_get('post_max_size'));
67-
68-
function return_bytes($val)
69-
{
70-
$val = trim($val);
71-
$num = (int) rtrim($val, 'KMG');
72-
$last = strtolower($val[strlen($val) - 1]);
73-
74-
switch ($last) {
75-
// The 'G' modifier is available
76-
case 'g':
77-
$num = $num * 1024 * 1024 * 1024;
78-
break;
79-
case 'm':
80-
$num = $num * 1024 * 1024;
81-
break;
82-
case 'k':
83-
$num *= 1024;
84-
break;
85-
}
86-
87-
return $num;
88-
}
66+
echo 'post_max_size in bytes = ' . ini_parse_quantity(ini_get('post_max_size'));
8967
9068
?>
9169
]]>
@@ -95,7 +73,7 @@ function return_bytes($val)
9573
<![CDATA[
9674
9775
display_errors = 1
98-
register_globals = 0
76+
opcache.enable_cli = 0
9977
post_max_size = 8M
10078
post_max_size+1 = 9
10179
post_max_size in bytes = 8388608
@@ -126,9 +104,9 @@ post_max_size in bytes = 8388608
126104
<function>ini_get</function> will return the exact string stored in the
127105
&php.ini; file and <emphasis>NOT</emphasis> its <type>int</type>
128106
equivalent. Attempting normal arithmetic functions on these values
129-
will not have otherwise expected results. The example above shows one
130-
way to convert shorthand notation into bytes, much like how the PHP
131-
source does it.
107+
will not have otherwise expected results. The
108+
<function>ini_parse_quantity</function> function can be used to convert
109+
the shorthand notation into bytes.
132110
</para>
133111
</note>
134112
<note>
@@ -145,6 +123,7 @@ post_max_size in bytes = 8388608
145123
<simplelist>
146124
<member><function>get_cfg_var</function></member>
147125
<member><function>ini_get_all</function></member>
126+
<member><function>ini_parse_quantity</function></member>
148127
<member><function>ini_restore</function></member>
149128
<member><function>ini_set</function></member>
150129
</simplelist>

reference/info/functions/ini-parse-quantity.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ var_dump(ini_parse_quantity('10F'));
7777
?>
7878
]]>
7979
</programlisting>
80-
&example.outputs.similar;
80+
&example.outputs;
8181
<screen>
8282
<![CDATA[
8383

0 commit comments

Comments
 (0)