PHP basic configuration: PHP's most commonly used INI function

Source: Internet
Author: User

PHP's configuration function is a few ini_* functions, mainly for the operation of the configuration file, in fact, four functions: Ini_get, Ini_set, Ini_get_all, Ini_restore. The most useful thing about personal feeling is ini_set and ini_get.

* Ini_get (): Gets the option value of the configuration file

This function is believed by many people to get the value of one of the options in the configuration file, return 1 if the value is true, and return 0 if the value is false, and the string will return the string.

For example in the manual:

/*
Our php.ini contains the following settings:

Display_errors = On
Register_globals = Off
Post_max_size = 8M
*/
echo ' display_errors = '. Ini_get (' display_errors '). "\ n"; Show whether the error is turned on
echo ' register_globals = '. Ini_get (' register_globals '). "\ n";/whether the global variable is open
echo ' post_max_size = '. Ini_get (' Post_max_size '). "\ n";/maximum file size to submit
echo ' post_max_size+1 = '. (Ini_get (' post_max_size ') +1). "\ n";
? >

Output:

Display_errors = 1
register_globals = 0
Post_max_size = 8M
Post_max_size+1 = 9

This function is mainly to get the configuration file, you can easily do a lot of operations. For example, you want to manipulate string filtering, but it's not clear if MAGIC_QUOTES_GPC is open, so you can write a function like this:

/* String Filter function * *
function Stringfilter ($STR)
{
if (Ini_get (' magic_quotes_gpc) ') {
return $str;
} else {
Return addslashes ($STR);
}
}

Of course, if you don't know if your global variable is open, you can also customize such a function:

/* Variable detection function * *
function Getgetvar ($var)
{
if (Ini_set (' register_gobals ')) {
return $var;
} else {
Return $_get[' var '];
}
}

Of course, you can do a lot of use, your own slowly experience.



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.