title: PHP read text from file then fill fields
body: <p>I've a page that shows some fields that can be saved to a file by the following code:</p>
  
  <pre><code>&lt;?php
  
  if($_POST['Submit'])
  {
  $company = $_POST['company'];
  $address1 = $_POST['address1'];
  $address2 = $_POST['address2'];
  $address3 = $_POST['address3'];
  $address4 = $_POST['address4'];
  $contact = $_POST['contact'];
  $contact2 = $_POST['contact2'];
  $phone = $_POST['phone'];
  
  $data = "$company \n $address1 \n $address2 \n $address3 \n $address4 \n $contact \n $contact2 \n $phone\n";
  
  //open the file
  $fh = fopen("/cfg/customers.txt", "a");
  fwrite($fh, $data);
  
  //close the file
  fclose($fh);
  
  print "Information Submitted. Thanks";
  }
  else
  {
  print &lt;&lt;&lt;ENDOFTXT
  &lt;/style&gt;&lt;form name="form1" method="post" action="index.php"&gt;
  &lt;table width="780" border="0" align="center"&gt;
  &lt;tr&gt;
  &lt;td width="256"&gt;&lt;span class="style5"&gt;Company Name:&lt;/span&gt;&lt;/td&gt;
  &lt;td width="514"&gt;&lt;input name="company" type="text" id="company"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;&lt;span class="style5"&gt;Address
  :&lt;/span&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input name="address1" type="text" id="address1" value=""&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;span class="style5"&gt;Unit / Apt :&lt;/span&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input name="address2" type="text" id="address2"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;span class="style5"&gt;City, Pr : &lt;/span&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input name="address3" type="text" id="address3"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;span class="style5"&gt;Postal Code :&lt;/span&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input name="address4" type="text" id="address4"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;span class="style5"&gt;Contact Name: &lt;/span&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input name="contact" type="text" id="contact" value="First Name Last Name"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;span class="style5"&gt;Email: &lt;/span&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input name="contact2" type="text" id="contact2"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;span class="style5"&gt;Phone :&lt;/span&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input name="phone" type="text" id="phone" value="( ) "&gt;
  &lt;input name="Submit" type="submit" class="style5" value="Submit"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td colspan="2"&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;p align="center"&gt;&amp;nbsp;&lt;/p&gt;
  &lt;/form&gt;
  ENDOFTXT;
  }
  ?&gt;
  </code></pre>
  
  <p>Now, I can read the text file using the follwoing code:</p>
  
  <pre><code>&lt;?php
  $lines = file("/cfg/customers.txt");
  $top200 = array_slice(array_reverse($lines),0,200);
  foreach($top200 as $line)
  {
      echo $line . "&lt;br /&gt;";
  }
  
  ?&gt;
  </code></pre>
  
  <p>But how can I put back to the original fields when the page loads for the first time?
  So, how can I merge the read routine to the above code?</p>