(PHP 4, PHP 5, PHP 7)
parse_ini_file — 锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟侥硷拷
$filename
[, bool $process_sections
= false
[, int $scanner_mode
= INI_SCANNER_NORMAL
]] ) : array
parse_ini_file() 锟斤拷锟斤拷一锟斤拷锟斤拷
filename
指锟斤拷锟斤拷 ini
锟侥硷拷锟斤拷锟斤拷锟斤拷锟斤拷锟叫碉拷锟斤拷锟斤拷锟斤拷为一锟斤拷锟斤拷锟斤拷锟斤拷锟介返锟截★拷
ini 锟侥硷拷锟侥结构锟斤拷 php.ini 锟斤拷锟斤拷锟狡★拷
filename
要锟斤拷锟斤拷锟斤拷 ini 锟侥硷拷锟斤拷锟侥硷拷锟斤拷锟斤拷
process_sections
锟斤拷锟斤拷锟斤拷锟斤拷锟�
process_sections
锟斤拷锟斤拷锟斤拷为
TRUE
锟斤拷锟斤拷锟矫碉拷一锟斤拷锟斤拷维锟斤拷锟介,锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟侥硷拷锟斤拷每一锟节碉拷锟斤拷锟狡猴拷锟斤拷锟矫★拷process_sections
锟斤拷默锟斤拷值锟斤拷 FALSE
锟斤拷
scanner_mode
Can either be INI_SCANNER_NORMAL
(default) or
INI_SCANNER_RAW
. If INI_SCANNER_RAW
is supplied, then option values will not be parsed.
锟缴癸拷时锟皆癸拷锟斤拷锟斤拷锟斤拷 array 锟斤拷锟斤拷锟斤拷锟矫o拷失锟斤拷时锟斤拷锟斤拷 FALSE
锟斤拷
锟芥本 | 说锟斤拷 |
---|---|
5.3.0 |
Added optional scanner_mode parameter.
Single quotes may now be used around variable assignments.
Hash marks (#) may no longer be used as comments
and will throw a deprecation warning if used.
|
5.2.7 |
On syntax error this function will return FALSE rather than an empty
array.
|
5.2.4 | 锟斤拷锟斤拷锟斤拷锟斤拷傻募锟斤拷锟斤拷锟叫★拷锟斤拷锟斤拷岜� PHP 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟� 0 锟斤拷头锟斤拷锟斤拷锟街会被锟斤拷锟斤拷锟剿斤拷锟狡讹拷锟斤拷 0x 锟斤拷头锟侥会被锟斤拷锟斤拷十锟斤拷锟斤拷锟狡★拷 |
5.0.0 | 锟矫猴拷锟斤拷也锟斤拷始锟斤拷锟斤拷选锟斤拷值锟节碉拷锟斤拷锟叫★拷 |
4.2.1 | 锟斤拷锟斤拷锟斤拷也锟斤拷始锟杰碉拷锟斤拷全模式锟斤拷 open_basedir 锟斤拷影锟届。 |
Example #1 sample.ini 锟斤拷锟斤拷锟斤拷
; This is a sample configuration file ; Comments start with ';', as in php.ini [first_section] one = 1 five = 5 animal = BIRD [second_section] path = "/usr/local/bin" URL = "http://www.example.com/~username" [third_section] phpversion[] = "5.0" phpversion[] = "5.1" phpversion[] = "5.2" phpversion[] = "5.3"
Example #2 parse_ini_file() 锟斤拷锟斤拷
锟斤拷锟斤拷也锟斤拷锟斤拷锟斤拷 ini 锟侥硷拷锟叫憋拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 parse_ini_file() 之前锟斤拷锟斤拷锟剿筹拷锟斤拷锟斤拷为 ini 锟斤拷值锟斤拷锟斤拷锟结被锟斤拷锟缴碉拷锟斤拷锟斤拷锟饺ワ拷锟街伙拷锟� ini 锟斤拷值锟结被锟斤拷值锟斤拷锟斤拷锟界:
<?php
define('BIRD', 'Dodo bird');
// Parse without sections
$ini_array = parse_ini_file("sample.ini");
print_r($ini_array);
// Parse with sections
$ini_array = parse_ini_file("sample.ini", true);
print_r($ini_array);
?>
锟斤拷锟斤拷锟斤拷锟教碉拷锟斤拷锟斤拷锟斤拷锟斤拷冢锟�
Array ( [one] => 1 [five] => 5 [animal] => Dodo bird [path] => /usr/local/bin [URL] => http://www.example.com/~username [phpversion] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.2 [3] => 5.3 ) ) Array ( [first_section] => Array ( [one] => 1 [five] => 5 [animal] => Dodo bird ) [second_section] => Array ( [path] => /usr/local/bin [URL] => http://www.example.com/~username ) [third_section] => Array ( [phpversion] => Array ( [0] => 5.0 [1] => 5.1 [2] => 5.2 [3] => 5.3 ) ) )
Example #3 parse_ini_file() parsing a php.ini file
<?php
// A simple function used for comparing the results below
function yesno($expression)
{
return($expression ? 'Yes' : 'No');
}
// Get the path to php.ini using the php_ini_loaded_file()
// function available as of PHP 5.2.4
$ini_path = php_ini_loaded_file();
// Parse php.ini
$ini = parse_ini_file($ini_path);
// Print and compare the values, note that using get_cfg_var()
// will give the same results for parsed and loaded here
echo '(parsed) magic_quotes_gpc = ' . yesno($ini['magic_quotes_gpc']) . PHP_EOL;
echo '(loaded) magic_quotes_gpc = ' . yesno(get_cfg_var('magic_quotes_gpc')) . PHP_EOL;
?>
锟斤拷锟斤拷锟斤拷锟教碉拷锟斤拷锟斤拷锟斤拷锟斤拷冢锟�
(parsed) magic_quotes_gpc = Yes (loaded) magic_quotes_gpc = Yes
Note:
锟斤拷锟斤拷锟斤拷锟斤拷 php.ini 锟侥硷拷没锟叫癸拷系锟斤拷锟斤拷锟侥硷拷锟斤拷锟斤拷锟叫脚憋拷时锟斤拷锟窖撅拷锟斤拷锟斤拷锟斤拷恕锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟饺★拷锟斤拷约锟斤拷锟接︼拷贸锟斤拷锟斤拷锟斤拷锟斤拷锟侥硷拷锟斤拷
Note:
锟斤拷锟� ini 锟侥硷拷锟叫碉拷值锟斤拷锟斤拷锟轿何凤拷锟斤拷母锟斤拷锟街碉拷锟街凤拷锟斤拷锟斤拷要锟斤拷锟斤拷锟斤拷锟斤拷双锟斤拷锟斤拷锟叫o拷"锟斤拷锟斤拷
Note: 锟斤拷些锟斤拷锟斤拷锟街诧拷锟斤拷锟斤拷为 ini 锟侥硷拷锟叫的硷拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷null锟斤拷yes锟斤拷no锟斤拷true 锟斤拷 false锟斤拷值为 null锟斤拷no 锟斤拷 false 锟斤拷效锟斤拷 ""锟斤拷值为 yes 锟斤拷 true 锟斤拷效锟斤拷 "1"锟斤拷锟街凤拷 {}|&~![()" 也锟斤拷锟斤拷锟斤拷锟节硷拷锟斤拷锟斤拷锟轿何地凤拷锟斤拷锟斤拷锟斤拷锟斤拷些锟街凤拷锟斤拷选锟斤拷值锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷濉�