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


<?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