This article mainly introduces how to use ini_get to obtain php. the variable value method in ini analyzes the ini_get function usage skills. For more information, see the example in this article. method of variable value in ini. Share it with you for your reference. The specific analysis is as follows:
To get php. you can use phpinfo (); to obtain all the php configuration information, but how do you get a variable value?
Php provides a function to obtain the variable value in php. ini: ini_get ()
The usage of ini_get () is very simple. the following example shows how to use it.
Syntax:
string ini_get ( string varname )
The return value is 0 or 1 if it is Boolean.
Instance:
<?php/*Our php.ini contains the following settings:display_errors = Onregister_globals = Offpost_max_size = 8M*/echo 'display_errors = ' . ini_get('display_errors') . "\n";echo 'register_globals = ' . ini_get('register_globals') . "\n";echo 'post_max_size = ' . ini_get('post_max_size') . "\n";echo 'post_max_size+1 = ' . (ini_get('post_max_size')+1) . "\n";echo 'post_max_size in bytes = ' . return_bytes(ini_get('post_max_size'));function return_bytes($val) { $val = trim($val); $last = strtolower($val[strlen($val)-1]); 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;}?>
The running result of the above code is similar to the following:
display_errors = 1register_globals = 0post_max_size = 8Mpost_max_size+1 = 9post_max_size in bytes = 8388608
If you want to obtain the variable value in the entire php. ini file, use the ini_get enhancement function ini_get_all ().
The ini_get_all () function returns the environment variables of the entire php in the form of arrays, which is also easy to use.
Instance 1:
<?phpprint_r(ini_get_all("pcre"));print_r(ini_get_all());?>
The running result of the above code is similar to the following:
Array( [pcre.backtrack_limit] => Array ( [global_value] => 100000 [local_value] => 100000 [access] => 7 ) [pcre.recursion_limit] => Array ( [global_value] => 100000 [local_value] => 100000 [access] => 7 ))Array( [allow_call_time_pass_reference] => Array ( [global_value] => 0 [local_value] => 0 [access] => 6 ) [allow_url_fopen] => Array ( [global_value] => 1 [local_value] => 1 [access] => 4 ) ...)
Example 2:
<?phpprint_r(ini_get_all("pcre", false)); // Added in PHP 5.3.0print_r(ini_get_all(null, false)); // Added in PHP 5.3.0?>
The output result is similar to the following:
Array( [pcre.backtrack_limit] => 100000 [pcre.recursion_limit] => 100000)Array( [allow_call_time_pass_reference] => 0 [allow_url_fopen] => 1 ...)
The function opposite to ini_get () is ini_set (), and ini_set has the function of changing php. ini settings. For example, when a script times out, you can set its maximum execution time.
I hope this article will help you with php programming.