PHP ini_get() 返回值的几个特殊点
阅读(2892)
<?php
/*
* php.ini 包含了以下的设置:
* 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 in bytes = ' . return_bytes(ini_get('post_max_size'));
function return_bytes($val) {
$val = trim($val);
$last = strtolower($val[strlen($val)-1]);
switch($last) {
// 自 PHP 5.1.0 起可以使用修饰符 'G'
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}
return $val;
}
?>
结果为:
display_errors = 1 register_globals = 0 post_max_size = 8M post_max_size in bytes = 8388608
几个特殊点:
- on/off代表的boolean值会转化为“1”/“0”
- 和内存size相关的值,会如实返回配置的写法,而不会转化为整型,如“8M”