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
