Counting lines in a file : feof « File Directory « PHP






Counting lines in a file

 
<?php
$lines = 0;

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








Related examples in the same category

1.Reading lines from a file
2.feof.php
3.Read till the end of a file