I am making a remarkably simple PHP blog that takes txt files from the directory and shows them, one to another, on the PHP page. This really is fine, but I am likely to have 365 of those files so it would be nice to exhibit them on multiple pages, Wordpress-style. An amount the PHP be to create these pages quickly, say, to show 20 files per page?

The PHP I must display the files is the following:

function printFile($file) {
  $handle = fopen("$file", "r");
  while (!feof($handle)) {
    echo fgets($handle) . "<br>";
  }
  echo "<hr>";
  fclose($handle);
}



$files = scandir($directory); 
$number = count($files, 0);
while ($number > 2) {
  $number--; 
  $FileToPrint = $directory . $files["$number"];
  echo $FileToPrint . "<br>";
  printFile("$FileToPrint");
}   

This will provide you with a concept:

// initialize some settings
$perPage = 20;
$page = intval($_GET['page']);

// getting the files (just *.txt)
$files = glob('directory/*.txt');
$numFiles = count($files);

// displaying the files for this page
$offset = $page * $perPage;
for($i = $offset; $i < ($offset + $perPage); $i++){
    // just print the filename for now
     echo $files[$i]. "<br>";
}


// page browser
$numPages = ceil($numFiles / $perPage);
for($i = 0; $i < $numPages; $i++){
    echo '<a href="yourpage.php?page='.$i.'">'.$i.'</a>';
}