I have this function:
function update_config($config)
{
$buffer = array();
$buffer[] = '<?php';
foreach( $config as $key => $value ) {
$buffer[] = '$config[\'' .$key. '\'] = \'' .str_replace('\'', ''', $value). '\';';
}
$buffer[] = '?>';
$data = implode("\n", $buffer);
$path = $_SERVER['DOCUMENT_ROOT'] . 'settings.php';
$fp = fopen($path, 'wb');
if ($fp) {
flock($fp, LOCK_EX);
$len = strlen($data);
fwrite($fp, $data, $len);
flock($fp, LOCK_UN);
fclose($fp);
}
}
is working very well, it insert like this $config[title] = 'Demo title';
How I can make to don't overwrite all file when I change something? Exemple, if I have 3 entries in settings.php and when I want to insert another, file is totaly rewrited with new insert only!
And I want when some exist like $config[title] change only value!
Thank you!