Mega Code Archive

 
Categories / Php / File Directory
 

Counting records in a file

<?php $records = 0; $record_separator = '--end--'; if ($fh = fopen('great-american-textfile-database.txt','r')) {   while (! feof($fh)) {     $s = rtrim(fgets($fh));     if ($s == $record_separator) {       $records++;     }   } } print $records; ?>