Oh, so you want to write a text file that happens to contain PHP code?
<?php
$new_name = 'life';
$new_user = 'abnfire';
...
$fp=fopen('config_file.php','r');
fwrite($fp,"<?php\n");
fwrite($fp,"\$db_name='$new_name';\n");
fwrite($fp,"\$db_user='$new_user';\n");
...
fwrite($fp,"?>\n");
fclose($fp);
?>
[Writing that very conservatively so's the syntax highlighting doesn't get confused and confuse.]