Dreamhost

Looking for somewhere to host your site? Browse our PHP web hosts section!

Home > Code Snippets > Count the number of lines in a text file

Count the number of lines in a text file

Description

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.

The code


Deprecated: Function eregi_replace() is deprecated in /home/totallyphpuk/totallyphp.co.uk/functions/function.syntaxHighlight.php on line 29

Deprecated: Function eregi_replace() is deprecated in /home/totallyphpuk/totallyphp.co.uk/functions/function.syntaxHighlight.php on line 30
<?php
  $file 
"somefile.txt";

  
$lines count(file($file));

  echo 
"There are $lines lines in $file";
?>

Get the code

Download the file to your computer: Click here to get the file