Skip to content

Instantly share code, notes, and snippets.

@robwilkerson
Created December 1, 2011 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robwilkerson/1417751 to your computer and use it in GitHub Desktop.
Save robwilkerson/1417751 to your computer and use it in GitHub Desktop.
Extremely simple PHP sample to count and return the number of lines in a text file. The output can be customised to suit your own requirements. It even seems to handle line endings nicely.
<?php
# As seen at http://www.totallyphp.co.uk/count-the-number-of-lines-in-a-text-file
$file = 'somefile.txt';
$lines = count( file( $file ) );
printf( 'There are %d line(s) in %s', $lines, $file );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment