What’s within “test.ini”:
[names] me = Robert you = Peter [urls] first = “http://www.example.com” second = “https://www.w3schools.com” |
PHP script:
<?php print_r(parse_ini_file(“test.ini”)); ?> |
The following is the result of the code above:
Array ( [me] => Robert [you] => Peter [first] => http://www.example.com [second] => https://www.w3schools.com ) |
An configuration (ini) file is parsed by the parse_ini_file() method, which then returns the settings.
Advice: This function is unrelated to the php.ini file and can be used to read in your own configuration files.
Note: The following reserved words—null, yes, no, true, false, on, off, and none—must not be used as keys for ini files. Moreover, the key cannot contain any of the reserved letters {}|&~!()^”.
parse_ini_file(file, process_sections, scanner_mode) |
Parameter |
Description |
file |
Essential. indicates which ini file to parse. |
process_sections |
Not required. It returns a multidimensional array containing section names and settings if set to TRUE. False is the default. |
scanner_mode |
Not required. may take on any of the subsequent values: • INI_SCANNER_TYPED (indicating that, when feasible, integer, boolean, and null types are retained). “Yes”, “on”, and “true” are changed to TRUE. “Off”, “no”, “false”, and “none” are changed to FALSE. NULL is created from “null”. If at all possible, numerical strings are transformed to integer type. |
Return Value: |
False on failure, array on success |
PHP Version: |
4.0+ |
PHP Changelog: |
PHP 7.0: # symbol (#) is not interpreted as a comment |
What’s within “test.ini”:
[names] me = Robert you = Peter [urls] first = “http://www.example.com” second = “https://www.w3schools.com” |
PHP script (process_sections = true):
<?php print_r(parse_ini_file(“test.ini”,true)); ?> |
The following is the result of the code above:
Array ( [names] => Array ( [me] => Robert [you] => Peter ) [urls] => Array ( [first] => http://www.example.com [second] => https://www.w3schools.com ) ) |