Answer the question
In order to leave comments, you need to log in
How to display the number of lines of files page by page?
Hello everyone, tell me how to implement, there is, say, 100 txt. files, they contain lines of different numbers, how to display the number of lines of files page by page .
I have already done this way, the thing is that it is displayed on all files, only one sum for the last file
$files = glob("../data/*.*");
$fnumber = '10';
foreach($files as $file){
$name[] = basename($file);
$size = round(filesize($file)/1024,2);
$count = count(file($file));
$summa += count(file($file));
}
$counts = count($files);
$pages = ceil($counts/$fnumber);
$page = $_GET['page'];
if(!$page OR $page=='')
{
$nav_min = 0;
$nav_max = $fnumber - 1;
}else{
$nav_min = ($page * $fnumber) - $fnumber;
$nav_max = ($fnumber * $page) - 1;
}
# Вывод
for($i = $nav_min; $i <= $nav_max; $i++)
{
echo $name[$i]; // выводится
echo $size; // НЕ выводится
echo $count; // НЕ выводится
}
echo $summa; // выводится
# Навигация
for($fpr = '', $i =1; $i <= $pages; $i++)
{
echo $fpr=(($i == 1 || $i == $pages || abs($i-$page) < 2) ? ($i == $page ? "<b style='font-size: 14px'>[$i]</b> | " : ' <a href="?page='.$i.'">'.$i.'</a> | ') : (($fpr == ' ... ' || $fpr == '')? '' : ' ... '));
}
Answer the question
In order to leave comments, you need to log in
If the case is on Linux and all the files are in the same folder, you can do this:
$path = 'dirname/*'; // все файлы из dirname
$result = shell_exec('wc -l ' . $path);
10 filename1.txt
17 filename2.txt
27 total
count(file($filename))
, saving the result to an array, summing it up in a separate variable along the way.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question