PHP/File Directory/feof

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

Counting lines in a file

 
<?php
$lines = 0;
if ($fh = fopen("data.txt","r")) {
  while (! feof($fh)) {
    if (fgets($fh)) {
      $lines++;
    }
  }
}
print $lines;
?>



feof.php

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



Reading lines from a file

 
<?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);
?>



Read till the end of a file

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