hello ,
i have simple php file similar to this style
<?php
// driver of database
$config['driver'] = 'mysql';
// database name
$config['database'] = 'a';
// database username
$config['username'] = 'user';
// database user password
$config['password'] = '123'
?>
so i wrote a function to modify values of any one of this variables
function modify($key,$value)
{
require('config.php');
$config[$key] = $value;
$handler = fopen('config.php','w');
$contents = "<?php";
foreach($config AS $a=>$b)
{
$contents .= '$config[\\''.$a.'\\'] = \\''.$b."';\
";
}
$contents .= "\
?>";
fwrite($handler,$contents);
fclose($handler);
}
and it’s work good … but my problem that i want when i use this function and it’s rewrite the config file … and want it to write the file with it’s first style (with // comments ) … because my current method will rewrite the config file and it will be like this (without // comments) :
<?php
$config['driver'] = 'mysql';
$config['database'] = 'a';
$config['username'] = 'user';
$config['password'] = '123'
?>
so is there any other method to solve my problem
?