title: How can I write to a file line by line or similar?
body: <p>In the code below, I simply replace all single quotes with double quotes from the original file.</p>
  
  <p>I got most of it done, I just need to write it to a file now.</p>
  
  <p>Should I store all the lines in memory and then write.</p>
  
  <p>Or write line by line?</p>
  
  <p>Which way is best</p>
  
  <pre><code>&lt;?php
  
      // http://stackoverflow.com/questions/5299471/php-parsing-a-txt-file
      // http://stackoverflow.com/questions/15131619/create-carriage-return-in-php-string
      // http://stackoverflow.com/questions/2424281/how-do-i-replace-double-quotes-with-single-quotes
  
  
      $txt_file    = file_get_contents('../js/a_file.js');
      $rows        = explode("\n", $txt_file);
      array_shift($rows);
  
      foreach($rows as $row =&gt; $data)
      {
          $data = str_replace("'", '"', $data);
  
          // echo "" . $row . " | "  . $data . "\r\n";
  
          // fwrite($myfile, $txt);
  
      }
  </code></pre>