ini_get Gets the value of a configuration option php函数


ini_get

(PHP 4, PHP 5)

ini_getGets the value of a configuration option

说明

string ini_get ( string $varname )

Returns the value of the configuration option on success.

参数

varname

The configuration option name.

返回值

Returns the value of the configuration option as a string on success, or an empty string for null values. Returns FALSE if the configuration option doesn't exist.

范例

Example #1 A few ini_get() examples

<?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) . " ";
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) {
        
// The 'G' modifier is available since PHP 5.1.0
        
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+1 = 9
post_max_size in bytes = 8388608

注释

Note: When querying boolean values

A boolean ini value of off will be returned as an empty string or "0" while a boolean ini value of on will be returned as "1". The function can also return the literal string of INI value.

Note: When querying memory size values

Many ini memory size values, such as upload_max_filesize, are stored in the php.ini file in shorthand notation. ini_get() will return the exact string stored in the php.ini file and NOT its integer equivalent. Attempting normal arithmetic functions on these values will not have otherwise expected results. The example above shows one way to convert shorthand notation into bytes, much like how the PHP source does it.

参见



相关阅读:
ini_get_all Gets all configuration options
ini_restore Restores the value of a configuration option
ini_set Sets the value of a configuration option
interface_exists 检查接口是否已被定义
intval 获取变量的整数值
in_array 检查数组中是否存在某个值
ip2long Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address
iptcembed 将二进制 IPTC 数据嵌入到一幅 JPEG 图像中
iptcparse 将二进制 IPTC http://www.iptc.org/ 块解析为单个标记
isset 检测变量是否设置
is_a 如果对象属于该类或该类是此对象的父类则返回 TRUE
is_array 检测变量是否是数组
is_bool 检测变量是否是布尔型
is_callable 检测参数是否为合法的可调用结构
快速导航

Copyright © 2016 phpStudy |