Replacing the variables in a file read by php
<p>I have a small app I am working on that generates configuration files. Because it may be used to generate a few different variants of configurations, I gather the variable values from the user, and then read in a template configuration from a file. That file has the names of the variables in it (i.e. $ip_address) at the proper positions. I have set those variables in my php code before reading and the printing out the files. However, the variable names are printed out, not the values of the variables:</p>

<pre><code>$hostname = $_POST['username'] . "_891";
$domain = $_POST['username'] . ".local";   
$routerFile = "891.txt";

$file_handle = fopen($routerFile, "r");
while (!feof($file_handle)) {
   $line = fgets($file_handle);
   print $line . "&lt;br /&gt;";
}
</code></pre>

<p>Output example:</p>

<blockquote>
  <p><code>hostname $hostname</code><br>
  <code>ip domain-name $domain</code></p>
</blockquote>

<p>How do I get php to replace the variables names with their stored values?</p>
