Modifing config files

Steve Meyers steve-plug at
Fri Feb 25 09:55:55 MST 2005

jeff wrote:
> Is there a command line tool that will let me modify the value of a
> config file.

You could do it in PHP fairly easily.  This is just a quick example, 
you'd really want to do some sanity checking on the arguments, and maybe 
have a usage output.


$config_file = $argv[1];
$section = $argv[2];
$key = $argv[3];
$value = $argv[4];

$config = parse_ini_file($config_file, true);

$config[$section][$key] = $value;

write_ini_file($config_file, $config);

function write_ini_file($config_file, $config) {
	$fp = fopen($config_file, 'w');
	foreach ($config as $section => $keys) {
		fwrite($fp, "[$section]\n");
		foreach ($keys as $key => $val) {
			fwrite($fp, "$key = \"$val\"\n");
		fwrite($fp, "\n");


More information about the PLUG mailing list