I have a script that saves it's certain settings, and such to a file periodically. I want to use this function that I wrote, but it doesn't work right.
The theory is as follows:
Each line is an entry
In the format of:
$config=yes/no;
or
$config="this is a string"
Should update a line if it finds $config somewhere in the file...
If it doesn't, it should write a new line on the bottom.
$writeval = "";
$filename = "$this->configfile";
$fp = fopen($filename, "r");
$maildatabase = fread($fp, filesize($filename));
fclose($fp);
$line = explode("\n", $maildatabase);
while ($i <= sizeof($line)) {
$data_pair = explode("=", $line[$i]);
if ($config == $data_pair[0]) {
if ($type == "string") {
print "a";
$writeval .= "$config=\"$value\"\n";
} else {
print "b";
$writeval .= "$config=$value;\n";
}
} else {
print "c....$line[$i],...";
$writeval .= $line[$i];
}
$i++;
}
Problem is it always overwrites the file. Any ideas why? How can I get this working? It's driving me nuts.