The parse_ini_file() function parses a configuration file (ini file) and returns the settings in an array.
parse_ini_file(file,process_sections)
parameter | describe |
---|---|
file | Required. Specifies the ini file to be checked. |
process_sections | Optional. If set to TRUE, returns a multidimensional array containing the name and settings of each section in the configuration file. The default is FALSE. |
Tip: This function can be used to read the configuration file of your own application and has nothing to do with the php.ini file.
Note: Some reserved words cannot be used as key names in ini files, including: null, yes, no, true and false. The characters {}|&~![()" also cannot be used anywhere in the key name.
Contents of "test.ini":
[names]me = Robertyou = Peter[urls]first = "http://www.example.com" second = "http://www.w3cschool.cc"
PHP code:
<?phpprint_r(parse_ini_file("test.ini"));?>
The above code will output:
Array([me] => Robert[you] => Peter[first] => http://www.example.com[second] => http://www.w3cschool.cc)
Contents of "test.ini":
[names]me = Robertyou = Peter[urls]first = "http://www.example.com" second = "http://www.w3cschool.cc"
PHP code (process_sections set to true):
<?phpprint_r(parse_ini_file("test.ini",true));?>
The above code will output:
Array([names] => Array ( [me] => Robert [you] => Peter )[urls] => Array ( [first] => http://www.example.com [second] => http: //www.w3cschool.cc ))