PHP parse_ini_file() Function
Complete PHP Filesystem Reference Manual
Definition and Usage
The parse_ini_file() function parses a configuration (ini) file and returns its settings as an array.
Syntax
parse_ini_file(file,process_sections)
| Parameters | Description |
|---|---|
| file | Required. Specifies the ini file to check. |
| process_sections | Optional. If set to TRUE, returns a multidimensional array including the names and settings of each section in the configuration file. Default is FALSE. |
Tips and Notes
**Tip:** This function can be used to read your own application's configuration files; it has nothing to do with php.ini.
**Note:** Some reserved words cannot be used as key names in an ini file, including: null, yes, no, true, and false. The characters {}|&~![()" also cannot be used anywhere in a key name.
Example 1
Contents of "test.ini":
[names]
me = Robert
you = Peter
[urls]
first = "http://www.example.com"
second = "https://www.runoob.com"
PHP code:
The code above will output:
Array
(
[me] => Robert
[you] => Peter
[first] => http://www.example.com
[second] => https://www.runoob.com
)
Example 2
Contents of "test.ini":
[names]
me = Robert
you = Peter
[urls]
first = "http://www.example.com"
second = "http://www.w3cschool.cc"
PHP code (process_sections set to true):
The code above will output:
Array
(
[names] => Array
(
[me] => Robert
[you] => Peter
)
[urls] => Array
(
[first] => http://www.example.com
[second] => http://www.w3cschool.cc
)
)
Complete PHP Filesystem Reference Manual