Snippets v2

Languages
My Snippets

Number of Lines in a file using PHP Login or Register to Bookmark this snippet

Description PHP

Given the file test.txt this snippet will count the number of lines.

The Code Download
  1. <?php
  2. $handle = fopen ("./test.txt", "r");
  3. $i =0;
  4. while (!feof ($handle)) {
  5.     $buffer = fgets($handle, 4096);
  6.     $i++;
  7. }
  8. fclose ($handle);
  9. echo $i;
  10. ?>
Credits Contact JC

Added by JC on 12th November, 2007

Comments

There are no comments about this snippet.

Post Comment HTML is allowed

You must be registered and logged in to post a comment.

Login here to post a comment