Home > php教程 > php手册 > body text

针对PHP配置文件 PHP最常用的ini函数

WBOY
Release: 2016-06-13 10:37:48
Original
791 people have browsed it

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 {
return addslashes($str);
}
}

当然,如果你无法知道你的全局变量是否打开,也可以定制这样的函数:

/* 变量检测函数 */
function getGetVar($var)
{
if (ini_set(register_gobals)) {
return $var;
} else {
return $_GET[var];
}
}

当然,你可以做很多用途,自己慢慢体会。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!