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.
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...
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example