Definition and Usage
The parse_ini_file[] function parses a configuration [ini] file and returns the settings in it in an array.
Syntax
parse_ini_file[file,process_sections]
file | Required. Specifies the ini file to check |
process_sections | Optional. If set to TRUE, it returns is a multidimensional array with section names and settings included. Default is FALSE |
Tips and Notes
Tip: This function can be used to read in your own application's configuration files, and has nothing to do with the php.ini file.
Note: The following reserved words must not be used as keys for ini files: null, yes, no, true, and false. Furthermore, there are also some reserved characters that must not be used in the keys: {}|&~![[]".
Example 1
Contents of "test.ini":
[names]
me =
Robert
you = Peter
[urls]
first = "//www.example.com"
second = "//www.w3schools.com"
PHP code:
The output of the code above will be:
Array
[
[me] => Robert
[you] => Peter
[first] => //www.example.com
[second] => //www.w3schools.com
]
Example 2
Contents of "test.ini":
[names]
me = Robert
you = Peter
[urls]
first = "//www.example.com"
second = "//www.w3schools.com"
PHP code [with process_sections set to true]:
The output of the code above will be:
Array
[
[names] => Array
[
[me] => Robert
[you] => Peter
]
[urls] => Array
[
[first] => //www.example.com
[second] => //www.w3schools.com
]
]
Complete PHP Filesystem Reference
PHP function parse_ini_file[] and example
In this part of the tutorial we will learn about the function parse_ini_file[] in context of file handling. And also we will see the example related to the parse_ini_file[] function
In this part of the tutorial we will learn about the function parse_ini_file[] in context of file handling. And also we will see the example related to the parse_ini_file[] function
Syntax of PHP parse_ini_file[] Function
- It is used to parse ini file.ini.
- file.ini is configuration file
- After parsing it returns the settings of the ini file in array form
PHP parse_ini_file[] Function with Example
Code For PHP parse_ini_file[] Function
make a sample.ini with the content
name = roseindia
domain= net
[second_section]
path = "/usr/local/bin"
URL = "//www.roseindia.net"
[third_section]
phpversion[] = "5.0"
phpversion[] = "5.1"
phpversion[] = "5.2"
phpversion[] = "5.3"
Output
name->roseindia
domain->net
path->/usr/local/bin
URL->//www.roseindia.net
phpversion->Array
Definition and Usage
The parse_ini_file[] function parses a configuration [ini] file and returns the settings in it in an array.
Syntax
parse_ini_file[file,process_sections]
file | Required. Specifies the ini file to check |
process_sections | Optional. If set to TRUE, it returns is a multidimensional array with section names and settings included. Default is FALSE |
Tips and Notes
Tip: This function can be used to read in your own application's configuration files, and has nothing to do with the php.ini file.
Note: The following reserved words must not be used as keys for ini files: null, yes, no, true, and false. Furthermore, there are also some reserved characters that must not be used in the keys: {}|&~![[]".
Example 1
Contents of "test.ini":
[names]
me =
Robert
you = Peter
[urls]
first = "//www.example.com"
second = "//www.w3schools.com"
PHP code:
The output of the code above will be:
Array
[
[me] => Robert
[you] => Peter
[first] => //www.example.com
[second] => //www.w3schools.com
]
Example 2
Contents of "test.ini":
[names]
me = Robert
you = Peter
[urls]
first = "//www.example.com"
second = "//www.w3schools.com"
PHP code [with process_sections set to true]:
The output of the code above will be:
Array
[
[names] => Array
[
[me] => Robert
[you] => Peter
]
[urls] => Array
[
[first] => //www.example.com
[second] => //www.w3schools.com
]
]