Here is what I wrote:
function readconfig($config, $value){
$configdat = file("$this->configfile","w");
for($i = 0; $i < sizeof($configdat); $i++) {
// Find thee config line
preg_match ("/$config/i", "$configdat[$i]", $result);
if (!$result[0])
continue;
$config = explode("=", $configdat[$i]);
$value = substr($config[1], 0, strlen($config[1])-2);
if (strchr(substr($value, 0, 1), "\"")) {
$value = substr($value, 1, strlen($value)-1);
}
return $value;
}
}
function writeconfig($config, $value, $type){
$configdat = file("$this->configfile","w");
$i = 0;
while ($configdat[$i]) {
if (!stristr($configdat[$i], $config)) {
$writeval .= "$configdat[$i]";
} else {
if ($type == "string"){
$writeval .= "$config=\"$value\";\n";
} else {
$writeval .= "$config=$value;\n";
}
}
$i++;
}
$configdat = fopen("$this->configfile", "w");
fputs($configdat, $writeval);
fclose($configdat);
return 1;
}
Does a good job at reading:
system.auto_update=true;
data.current_something=apple;
data.current_else="this is an orange";
But when I write a line as $type = string, it starts to get funny.
SHould write something like the last line of my example data file. It does... but when I read it using the function above, it no longer removes that last quote... assume that's because some extra character was inserted.
Any ideas how to correct this so it works reliably?
I think it has something with the return.