IniFile

Parse standard INI files using PHP's in built parse_ini_file(). Does not read in comments. No options are available for this container.

Reading a .ini file

Ini file

[database]
host=db.example.org
user=bloguser
pass=blogpassword
<?php
require_once 'Config.php';

$file dirname(__FILE__) . '/ini-file-read.txt';

$conf = new Config();
$root $conf->parseConfig($file'inifile');
if (
PEAR::isError($root)) {
    echo 
'Error reading config: ' $root->getMessage() . "\n";
    exit(
1);
}

$cfg $root->toArray();

echo 
"Database connection:\n";
echo 
' Host:     ' $cfg['root']['database']['host'] . "\n";
echo 
' User:     ' $cfg['root']['database']['user'] . "\n";
echo 
' Password: ' $cfg['root']['database']['pass'] . "\n";

?>

Output

    Database connection:
 Host:     db.example.org
 User:     bloguser
 Password: blogpassword

   
IniCommented (Previous) PHPArray (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.