Question: ```
<!DOCTYPE html>
<html>
<head>
   <title></title>
</head>
<body>
   <table>
      <form name="form" method="POST" action="">
         <tr><td colspan="2" align="center"> Database </tr>
         <tr><td>Servername:</td>
         <td><input type="text" name="servername" value="" ></td></tr>
         <tr><td>Username:</td>
             <td><input type="text" name="username" value="" ></td>
         </tr>
         <tr><td>Password:</td>
             <td><input type="text" name="password" value="" ></td>
         </tr>
         <tr><td>Database Name:</td>
             <td><input type="text" name="dbname" value=""> </td>
         </tr>
         <tr><td colspan="2" align="center"><input type="submit" name="submit" ></td</tr>
      </form>
   </table>
</body>
</html>

```

I want a create a php config file, using the values of the form. I can't understand How can i do this. I'm learner now so please suggest me..

Answer: 
Simple example:

```
// save to file
$post = json_encode($POST);
file_put_contents('config.txt', $post);

// read from file
$post1 = file_get_contents('config.txt');
$p = json_decode($post1);
// show array
print_r($p);
// show username
echo $p['username'];

```

Or php file

```
if (isset($_POST['username'])) {
    $php = '<?php
    $user = "'.$_POST['username'].'";
    $pass = "'.$_POST['pass'].'";
    ?>';
    file_put_contents('config.php', $php);
}

```
If this for config, you can:

* Just create file with `.php` extension and write some data using `file_put_contents` or `fwrite`. You need to write `<?php ?>` tags into file and variables that you want OR
* Copy previous created template and replace dummy values with `preg_replace` or something else. This is IMHO better and flexible solution.