dongyan8896 2011-12-07 13:55
浏览 34

获取文件的内容,通过给出指向php [duplicate]的指针

i have a huge file, going upto 10 MB.

I want to load the file using php in chunks. Also the file should be loaded in reverse order.

what i want to do is, provide a to and from file pointers or byte sizes where 0 means the last position of the file.

so if i say

0 - 5000, it would mean load from position : last -5000 to last

5000 - 10000, it would mean load from position : last - 10000 to last - 5000

</div>
  • 写回答

1条回答 默认 最新

  • dongyi1524 2011-12-07 14:07
    关注

    This may work for you?

    //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);
    
    评论

报告相同问题?