通过在php中给出from和to指针来获取文件的内容


fetch content of a file, by giving from and to pointers in php

我有一个很大的文件,有10mb。

我想用php在块中加载文件。此外,文件应该以相反的顺序加载。

我想做的是,提供一个to和from文件指针或字节大小,其中0表示文件的最后位置。

所以如果我输入

0 -5000,表示从位置:最后一个-5000到最后一个

5000 - 10000,表示从位置:last - 10000到last - 5000

这可能对你有用?

//opens file
$ctx = fopen('file.txt', 'r');
//number of lines from end to read
$number = 5000;
//move to end of file - $number
fseek($ctx, $number, SEEK_END);
//loop until end of file
while(!feof($ctx))
{
    $buffer = fgets($ctx);
}
fclose($ctx);