PHP/File Directory/feof

Материал из Web эксперт
Перейти к: навигация, поиск

Counting lines in a file

   <source lang="html4strict">

<?php $lines = 0; if ($fh = fopen("data.txt","r")) {

 while (! feof($fh)) {
   if (fgets($fh)) {
     $lines++;
   }
 }

} print $lines; ?>

 </source>
   
  


feof.php

   <source lang="html4strict">

<?php

  $fh = fopen("/home/www/data/users.txt", "rt");
  while (!feof($fh)) echo fgets($fh);
  fclose($fh);

?>

 </source>
   
  


Reading lines from a file

   <source lang="html4strict">

<?php $fh = fopen("orders.txt","r") or die($php_errormsg); while (! feof($fh)) {

   $s = fgets($fh,256);
   process_order($s);

} fclose($fh) or die($php_errormsg); ?>

 </source>
   
  


Read till the end of a file

   <source lang="html4strict">

<?

   $huge_file = fopen("VERY_BIG_FILE.txt", "r");
   while (!feof($huge_file)) {
           print fread($huge_file, 1024);
   }
   fclose($huge_file);

?>

 </source>