PHP » I/O » parse_ini_file()

Syntax:
array parse_ini_file(string filename [, bool use_sections])
filename
The name of the ini file.
use_sections
Whether to use sections or return a flat array.

Parses an ini file.

This function parses an ini file and returns the result as an associative array. If the optional use_sections is set to true, the array returned will be two-dimensional with the section name as the first key. Directive names in the ini file are followed by an equal sign and then the value. A semicolon starts a comment.

Examples

Code:
<!--
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Sample ini file for parse_ini_file.php
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

[db settings]
server = sqlhost
user = www
passwd = qwerty

[user]
self_register = yes
show_email = no
show_realname = yes

-->


<?php

$config = parse_ini_file("sample.ini", TRUE);
print "<pre>";
print_r($config);
print "</pre>";


?>
Output:
Array
(
   [db settings] => Array
       (
           [server] => sqlhost
           [user] => www
           [passwd] => qwerty
       )

   [user] => Array
       (
           [self_register] => 1
           [show_email] =>
           [show_realname] => 1
       )

)

Explanation:

This example shows the result of using parse_ini_file() with use_sections set to TRUE.