For example, when parse_ini_file( ) is given a
file with these contents:
; physical features
eyes=brown
hair=brown
glasses=yes
; other features
name=Susannah
likes=monkeys,ice cream,reading
The array it returns is:
Array
(
[eyes] => brown
[hair] => brown
[glasses] => 1
[name] => Susannah
[likes] => monkeys,ice cream,reading
)
Blank lines and lines that begin with ; in the
configuration file are ignored. Other lines with
name=value pairs are put into an array with the
name as the key and the value, appropriately, as the value. Words
such as on and yes as values
are returned as 1, and words such as off and
no are returned as the empty string.
Array
(
[physical] => Array
(
[eyes] => brown
[hair] => brown
[glasses] => 1
)
[other] => Array
(
[name] => Susannah
[likes] => monkeys,ice cream,reading
)
)
Your configuration file can also be a valid PHP file that you load
with require instead of parse_ini_file(
). If the file config.php contains:
<?php
// physical features
$eyes = 'brown';
$hair = 'brown';
$glasses = 'yes';
// other features
$name = 'Susannah';
$likes = array('monkeys','ice cream','reading');
?>
You can set the variables $eyes,
$hair, $glasses,
$name, and $likes with:
require 'config.php';