title: File I/O to textarea in PHP
body: <p>My friend and I have a little spare time home page together. He's not a programmer, and in order for him to be able to change some text on the front page, I created a php-script that</p>
  
  <p>1) Reads data from file "tester.txt" (this is the text that should go on the front page)<br>
  2) Prints this text to a textarea, where you can edit the text and submit it again<br>
  3) Writes the edited text to the same file, "tester.txt"</p>
  
  <p>The two functions Read(); and Write(); look like this</p>
  
  <pre><code>function Read() {
      $file = "tester.txt";
      $fp = fopen($file, "r");
      while(!feof($fp)) {
          $data = fgets($fp, filesize($file));
          echo "$data &lt;br&gt;";
      }
      fclose($fp);
  }
  
  function Write() {
      $file = "tester.txt";
      $fp = fopen($file, "w");
      $data = $_POST["tekst"];
      fwrite($fp, $data);
      fclose($fp);
  }
  </code></pre>
  
  <p>The only problem I have is that when the text is printed to a text area the line returns are written as <code>&lt;br&gt;</code> - and I don't really want it to do that, because when you edit some of the code and rewrites it, another layer of <code>&lt;br&gt;</code>'s appear. Here's a screenshot to illustrate:</p>
  
  <p><img src="https://i.stack.imgur.com/idGl0.png" alt="Test 1"></p>
  
  <p><img src="https://i.stack.imgur.com/wZz2I.png" alt="Test 2"></p>
  
  <p>Is there any workaround to this?</p>
  
  <p>Thanks!</p>
  
  <p>If you need the rest of the code, here it is:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Updater&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;?php
                 function Read() {
                     $file = "tester.txt";
                     $fp = fopen($file, "r");
                     while(!feof($fp)) {
                         $data = fgets($fp, filesize($file));
                         echo "$data &lt;br&gt;";
                     }
                     fclose($fp);
                 }
  
                 function Write() {
                     $file = "tester.txt";
                     $fp = fopen($file, "w");
                     $data = $_POST["tekst"];
                     fwrite($fp, $data);
                     fclose($fp);
                 }
          ?&gt;
  
          &lt;?php
          if ($_POST["submit_check"]){
              Write();
          };
          ?&gt;      
  
          &lt;form action="&lt;?php echo $_SERVER['PHP_SELF'] ?&gt;" method="post"&gt;
          &lt;textarea width="400px" height="400px" name="tekst"&gt;&lt;?php Read(); ?&gt;&lt;/textarea&gt;&lt;br&gt;
          &lt;input type="submit" name="submit" value="Update text"&gt;
          &lt;input type="hidden" name="submit_check" value="1"&gt;
          &lt;/form&gt;
  
                  &lt;?php
          if ($_POST["submit_check"]){
              echo 'Text updated';
          };
          ?&gt;      
  
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>