Connecting Tech Pros Worldwide Help | Site Map

PEAR::Config

Charlie Smith
Guest
 
Posts: n/a
#1: Jul 17 '05
Hello All

I'm writing a little app for my personal use and want to store the
configuration data in an xml file. I found PEAR::Config that lets
me read the config data into my app. But so far, I haven't figured
out how to get modifcations back to the xml file.

Here's what I've got so far. I ran across this basic code in an article
at DevShed.

<?php
require_once 'Config.php';

$conf = new Config;
$root =& $conf->parseConfig('/usr/local/apache/myapp.xml', 'XML');

if (PEAR::isError($root)) {
die('Error while reading configuration: ' . $root->getMessage());
}

$settings = $root->toArray();

printf('User settings<br>');
printf('=============<br>');
printf('dbhost: %s<br>',$settings['root']['connect']['dbhost']);
printf('dbuser: %s<br>',$settings['root']['connect']['dbuser']);
printf('dbpass: %s<br>',$settings['root']['connect']['dbpass']);
printf('dbname: %s<br>',$settings['root']['connect']['dbname']);

$conf->writeConfig('/usr/local/apache/myapp.xml', 'XML');
?>

What I want to able to do is modify the values in the settings array (not
the problem) and the write them back out to the xml file.

I understand that it takes all the data from the root level and assigns it
to an array called $settings. What I'm having trouble with is getting
$settings back to the file.

Has anyone else used PEAR::Config doing this sort of thing?

Thanks in advance

Charlie Smith

Closed Thread


Similar PHP bytes