All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
C#教程:线程同步
在MySQL中定义外键_php资料_编程技术
X-Space:日志发布后首页为何不更新-_php资料_编程技术
Zend,Framework,1.0正式版即将发布_php资料_编程技术
基于AJAX技术提高搜索引擎排名_[AJAX教程]
delphi获取当前目录
PHP汉字区位码相互转换源代码_[PHP教程]
ASP.NET,Forums,页面模型分析_.net资料_编程技术
实战经验:PHP+MySQL数据库论坛简易通_php资料_编程技术
Sql,server加密技术和SQL注入攻击_[SQL,Server教程]
Reading number is top 10 pictures
Sora aoi mirror memorial classics5
Hunan road lawenforcement vehicle pursue overload car caused the car turn and man is died
A man's favorite things3--ZhouWeiTong
这只猪到底犯了什么错?
30 beautiful school beauty5
Take you to walk into the most true north Korea rural1
Shandong jinan is about to dismantle a one hundred-year history of the building
初吻给了谁?
Summer is most suitable for young people to travel in China8
到南昌西站了2
Download software ranking
Unix video tutorial5
好色的外科大夫
功夫熊猫2(下集)
linux初级教程
ASP.NET.2.0.XML.高级编程(第3版)
The king of fighters 97(Mobile phone games-apk)
C#程序员参考手册
Boxer Classic video3
SP4 for SQL2000
Boxer's Top ten classic battle7
aaa published in(发表于) 2013/12/27 19:53:42 Edit(编辑)
PHP针对配置文件操作的最常用四个ini函数_php资料_编程技术

PHP针对配置文件操作的最常用四个ini函数_php资料_编程技术

PHP针对配置文件操作的最常用四个ini函数_php资料_编程技术-你的首页-uuhomepage.com

php的配置函数就是几个ini_*的函数,主要是针对配置文件的操作,其实就四个函数:ini_get、ini_set、ini_get_all、ini_restore。个人感觉最有用的就是ini_set和ini_get。

* ini_get():获取配置文件的选项值

这个函数相信很多人都使过,就是获取配置文件中某一个选项的值,如果是true值就返回1,如果是false值就返回0,字符串就返回字符串。

比如手册中的例子:

/*
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"; //显示错误是否打开
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";
?>

输出:

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'];
}
}

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

* ini_set函数:设置php.ini中的某些变量值

这个函数是设置选项中的值,在执行函数后生效,脚本结束的时候,这个设置也失效。不是所有的选项都能被改函数设置的。具体那些值能够设置,可以查看手册中的列表。
就是能够设置php.ini中的选项值比如,display_error选项关闭了,但是你要显示程序中的错误信息,方便你调试程序,那么就可以使用这个函数:

ini_set("display_errors", "On");

那么在你这个页面的程序都会显示错误信息了,而且你还可以使用error_reporting来设置显示的错误信息级别。

如果你需要增加脚本执行时间,那么可以设置:

ini_set("max_execution_time", "180");

那么脚本执行时间就由默认的30秒变为180秒,当然,你也可以使用set_time_limit()来设置。
其实你把ini_set和ini_get结合使的话,非常好。比如你想在配置文件里添加自己的包含文件路径,但是你有没有权限更改php.ini,那么你可以结合两个函数:

ini_set('include_path',ini_get('include_path').':/your_include_dir:');

* ini_get_all: 获取所有的设置选项变量

把所有选项值以数组的形式返回,方便你当phpinfo()无法使用的时候来使用。

手册例子,比如:

$inis = ini_get_all();
print_r($inis);
?>

部分输出:

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: 回复配置文件默认的值

就是回复配置文件默认的值,当你使用ini_set设置后可以使用它来恢复。





添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.