title: How to configure CodeIgniter database file based on user input using PHP?
body: <p>Suppose I have a database configuration form like the following image:  </p>
  
  <p><a href="https://i.stack.imgur.com/aoTcj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aoTcj.png" alt="Database Config"></a></p>
  
  <p>In CodeIgniter, the user needs to edit the files at <code>...\application\config\database.php</code> and change the  hostname, username, password and other required info.  </p>
  
  <p>Now I want to do the task automatically when a user fills out the above form and clicks the "Save" button.  I guess I need to perform some file write operation using PHP, but I don't know how to find and replace specific portions of a file.</p>
  
  <p>How can I change hostname, username, password, and database name based on the form input in the CodeIgniter database configuration file?</p>