php count lines in file – How to get the number of lines in a file using PHP?

php count lines in file – Efficiently counting the number of lines of a text file. This is a PHP function that will return the number lines in a text file. Use it to count lines in a data file.

php count lines in file

PHP – How to Calculate no of Lines in File?


PHP program to count the number of lines in a text file :

PHP Function to Count Lines in a Data Text File

Count lines a data text file

function isa_count_datafile_lines($file) {
    ini_set('memory_limit', '-1');
    $c = ( false === $arr) ? 0 : count($arr);
    set_time_limit(30);// restore to default
    ini_set('memory_limit','128M');// restore to default
    return $c;

php count files in directory


$file = '/tmp/product_details.txt';
$count = isa_count_datafile_lines($file);
echo 'There are ' . number_format($count) . ' lines in ' . $file;

I hope you get an idea about php count lines in file.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment