n-dimension arrays <-> ini files in PEAR Config
| From: | Andy Crain | Date: | Wed, 03 Dec 2003 23:56:18 +0000 |
| Subject: | n-dimension arrays <-> ini files in PEAR Config | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-9284@lists.php.net to get a copy of this message | ||
I'm unable to get PEAR::Config to convert properly between "inifile" and
"phparray" storage formats when the data to be stored is a multi-dimensional
array. Is it possible to do this? Specifically, if I build a
multi-dimensional array, then write it to an ini file, then read it back
into an array, the array is corrupted. The code below, a small modification
to part of /config/docs/inifromscratch.php, demonstrates the problem. The
array at the end of the process is very different from the array at the
beginning of the process. I'm wondering if this is a shortcoming of php's
parse_ini_file(), or if ini files can represent only one-dimensional arrays,
or if I'm doing something wrong. I'd really like to be able to store a
multi-dimensional array as an ini file and then reconstitute it, if
possible.
Thanks in advance,
Andy
require_once("Config.php");
$conf['storage']['driver'] = 'sql';
$conf['storage']['params']['phptype'] = 'mysql';
$conf['storage']['params']['hostspec'] = 'localhost';
$conf['storage']['params']['username'] = 'mamasam';
$conf['storage']['params']['password'] = 'foobar';
$c = new Config();
$root =& $c->parseConfig($conf, 'phparray');
echo 'BEFORE<br><pre>'. $root->toString('phparray',
array('name' =>
'before')) .'</pre><pre>';
print_r($root->toArray());
echo '</pre><p>';
if ($c->writeConfig('Config_Test.ini', 'inifile') === true) {
echo 'Config written into Config_Test.ini';
}
unset($c);
$c = new Config();
$root =& $c->parseConfig('Config_Test.ini', 'inifile');
echo 'AFTER<br><pre>'.$root->toString('phparray',
array('name' =>
'after')).'</pre><pre>';
print_r($root->toArray());
echo '</pre><p>';