PHP - How to Calculate no of Lines in File?

03-Apr-2023

.

Admin

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.

Example


<?php

function count_lines($file)

{

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

$count = 0;

while(fgets($handle))

{

$count++;

}

fclose($handle);

return $count;

}

$file='text.txt';

$count = count_lines($file);

echo $count;

?>

It will help you...

#PHP