background image

PHP 基础配置:PHP 最常用的 ini 函数

php 的配置函数就是几个 ini_*的函数,主要是针对配置文件的操作,其实就
四个函数:ini_get、ini_set、ini_get_all、ini_restore。个人感觉最有用的就是
ini_set 和 ini_get。
 
* ini_get():获取配置文件的选项值
 
这个函数相信很多人都使过,就是获取配置文件中某一个选项的值,如果是
true 值就返回 1,如果是 false 值就返回 0,字符串就返回字符串。
比如手册中的例子:
 
<?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') . " "; //显示错误是否打
开 
echo 'register_globals = ' . ini_get('register_globals') . " ";//全局变量是
否打开 
echo 'post_max_size = ' . ini_get('post_max_size') . " ";//最多能提交的
文件大小 
echo 'post_max_size+1 = ' . (ini_get('post_max_size')+1) . " "; 
?>
 
输出:
 
display_errors = 1 
register_globals = 0 
post_max_size = 8M 
post_max_size+1 = 9 
 
这个函数主要是为了获取配置文件,可以方便你很多操作。比如你想操作字符
串过滤,但是又不清楚 magic_quotes_gpc 有没有打开,所以你就可以这样
写一个函数:
/* 

 

字符串过滤函数 */

function stringFilter($str) 

if (ini_get('magic_quotes_gpc)') { 
return $str; 
} else {