title: Can I read a .TXT file with PHP?
body: <p>As I start the process of writing my site in PHP and MySQL, one of the first PHP scripts I've written is a script to initialize my database.  Drop/create the database.  Drop/create each of the tables.  Then load the tables from literals in the script.  </p>
  
  <p>That's all working fine!  Whoohoo :-)</p>
  
  <p>But I would prefer to read the data from files rather than hard-code them in the PHP script.  </p>
  
  <p>I have a couple of books on PHP, but they're all oriented toward web development using MySQL.  I can't find anything about reading and writing to ordinary files. </p>
  
  <p>Yes, I know there's a gazillion questions here on stackoverflow about reading TXT files, but when I look at each one, they're for C or C# or VB or Perl.  I'm beginning to think that PHP just can't read files :-(</p>
  
  <p>All I need is a brief PHP example of how to open a TXT file on the server, read it sequentially, display the data on the screen, and close the file, as in this pseudo-code:</p>
  
  <pre><code>program readfile;
  handle = open('myfile.txt');
  data = read (handle);
  while (not eof (handle)) begin
      display data;
      data = read (handle);
      end;
  close (handle);
  end;     
  </code></pre>
  
  <p>I will also need to write files on the server when I get to the part of my site where people upload avatars, and save them as JPG or GIF files.  But that's for later.</p>
  
  <p>Thanks!</p>