php count lines in file – Count number of lines in a file – Write a PHP script to count number of lines in a file. The file() function actually returns an array.
php count lines in file – PHP Function to Count Lines in a Data Text File
php count lines in file – How to count the number of lines in a file using php? – To explain it we assume a file named result.txt with two lines in it.
<?php $file = basename($_SERVER['PHP_SELF']); $total_cnt = count(file($file)); echo "There are $total_cnt lines in $file"."\n"; ?>
PHP – How to Calculate no of Lines in File?
<?php function total_lines($file) { $call_request = fopen( $file, "r" ); $total_cnt = 0; while(fgets($call_request)) { $total_cnt++; } fclose($call_request); return $total_cnt; } $file='result.txt'; $total_cnt = total_lines($file); echo $total_cnt; ?>
PHP program to count the number of lines in a text file :
<?php $call_request = "pakainfo_v1.txt"; $result_lines = file($call_request); $total_cnt= count($result_lines); echo $total_cnt; ?>
Example
<?php $filePath = "pakainfo_v1.txt"; $lines = count(file($filePath)); echo $lines; ?>
don’t Miss : Php Count Lines In File