Php uses ini_get to obtain the variable value in php. ini

Source: Internet
Author: User
This article mainly introduces how php uses ini_get to obtain the variable value in php. ini. The example shows how to use the ini_get function. For more information, see

This article mainly introduces how php uses ini_get to obtain the variable value in php. ini. The example shows how to use the ini_get function. For more information, see

This example describes how php uses ini_get to obtain the variable value in php. 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 = 8 M */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_byt Es (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.0case '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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.