PHP - How to Calculate no of Lines in File?

Feb 08, 2020



Hi Dev,

In this post, we will learn How to calculate no of lines in text file in php?. step by step explain How to count the number of lines of a file in php ?.

if you want to see example of PHP count number of lines in a file then you are a right place you can see php count line in file. Follow bellow tutorial step of php count line in text file.Type a message

I will give you one example for count number of lines in file PHP as bellow.



function count_lines($file)


$handle = fopen( $file, "r" );

$count = 0;






return $count;



$count = count_lines($file);

echo $count;


It will help you...