Function
I have not noticed before, listen to colleagues today, look at it immediately, powerful.
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:
<?php
/*
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.
* Ini_set function: Set some variable values in the PHP.ini
This function is to set the value in the option, which takes effect after the function is executed, and this setting is invalidated at the end of the script. Not all options can be changed by the function settings. The specific values can be set up to view the list in the manual.
is to be able to set the option value in php.ini For example, the Display_error option is turned off, but you want to display the error message in the program to facilitate your debugger, then you can use this function:
Ini_set ("Display_errors", "on");
Then the program on your page will display the error message, and you can also use error_reporting to set the error message level displayed.
If you need to increase the execution time of the script, you can set:
Ini_set ("Max_execution_time", "180");
Then the script execution time is changed from the default 30 seconds to 180 seconds, of course, you can also use Set_time_limit () to set.
In fact, you put Ini_set and ini_get together to make the words, very good. For example, if you want to add your own file path to the configuration file, but you have permission to change php.ini, then you can combine two functions:
Ini_set (' include_path ', Ini_get (' include_path '). ':/ Your_include_dir: ');
* Ini_get_all: Get all SET option variables
Return all the option values as an array to make it easier for you to use when Phpinfo () is unavailable.
Examples of manuals, such as:
<?php
$inis = Ini_get_all ();
Print_r ($inis);
?>
Partial output:
Array
(
[Allow_call_time_pass_reference] => Array
(
[Global_value] => 1
[Local_value] => 1
[Access] => 6
)
[Allow_url_fopen] => Array
(
[Global_value] => 1
[Local_value] => 1
[Access] => 7
)
...
)
* Ini_restore: Reply profile Default value
is to reply to the default value of the profile, which you can use to recover when you use Ini_set settings.
Author:heiyeluren
Writetime:2005-8-16