parse_ini_file
Parse a configuration file
parse_ini_file()
function parse a configuration file and returns the settings in it as an array.
Contents of "test.ini":
[names] me = Robert you = Peter [urls] first = "http://www.example.com" second = "http://www.gitbox.net"
PHP Code:
<?php print_r ( parse_ini_file ( "test.ini" ) ) ; ?>
Output:
Array ( [me] => Robert [you] => Peter [first] => http://www.example.com [second] => http://www.gitbox.net )
Contents of "test.ini":
[names] me = Robert you = Peter [urls] first = "http://www.example.com" second = "http://www.gitbox.net"
PHP code ( process_sections is set to true):
<?php print_r ( parse_ini_file ( "test.ini" , true ) ) ; ?>
Output:
Array ( [names] => Array ( [me] => Robert [you] => Peter ) [urls] => Array ( [first] => http://www.example.com [second] => http://www.gitbox.net ) )
parse_ini_file ( file , process_sections )
parameter | describe |
---|---|
file | Required. Specify the ini documents to be inspected. |
process_sections | Optional. If set to true, a multi-dimensional array is returned, including the name and settings of each section in the configuration file. The default is false. |
The structure of the ini file is similar to that of php.ini.
Constants can also be parsed in ini files, so if a constant is defined as the value of ini before running parse_ini_file()
, it will be integrated into the result. Only the value of ini will be evaluated.
Key names and sub-section names composed of numbers will be processed by PHP as integers, so numbers starting with 0 will be treated as octal and those starting with 0x will be treated as hexadecimal.