PHP Tutorial - PHP parse_ini_file() Function






Definition

The parse_ini_file() function parses an ini file and returns the settings in it in an array.

Syntax

PHP parse_ini_file() Function has the following syntax.

parse_ini_file(file,process_sections)

Parameter

ParameterIs RequiredDescription
fileRequired.ini file to check
process_sectionsOptional.TRUE means to return is a multidimensional array with section names and settings included. Default is FALSE

Return

The settings are returned as an associative array on success, and FALSE on failure.





Format of init file

Contents of an example "test.ini" file.

[names]
Developer = Bob
Tester = Mike
[urls]
first = "http://www.java2s.com"
second = "http://www.php.net"

Example

parse_ini_file() ignores section headers and returns each .ini key and its value as an associative array.

If you pass true as the second parameter, it makes each section header an element in the return value.


<?PHP
      $inifile = parse_ini_file("my.ini");
      var_dump($inifile);
      $inifile = parse_ini_file("my.ini", true);
      var_dump($inifile);
?>