Display files
  1. Create a new script with this code:

    <?php

    $myfile = fopen ('textthought.txt', 'r') or die ("Can not open file");

    while (!feof($myfile)){
    $line = fgets($myfile,5000);
    print "$line <br>"; }

    fclose($myfile);

    ?>
  2. Save the file as textviewer.php in the PHPSCRIPTS folder, upload it to the phpscripts directory on the Web server.

    Here's what the relevant lines in this script do:
  • $myfile = fopen ('textthought.txt', 'r') or die ("Can not open file");

    Opens the file textthought.txt in read-only mode, and assigns the text in it to the variable $myfile.

  • while (!feof($myfile)){

    This while loop loops through the $myfile variable one line at a time until it gets to the end-of-file.

    !feof means "not the end of the file."

    So, this line means: "Keep looping through each line in the $myfile file while it has 'not' (!) reached 'the end of the file' (feof)."

    When the program reaches the end of the file, it will exit the loop.