How to read only 5 last line of the text file in PHP?

前端 未结 18 1624
陌清茗
陌清茗 2020-11-28 08:45

I have a file named file.txt which is update by adding lines to it.

I am reading it by this code:

$fp = fopen(\"file.txt\", \"r\");
$da         


        
18条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 09:28

    The most of options here suppose to read file into the memory and then work with rows. This wouldnt be a good idea, if the file too large

    I think the best way is to use some OS-utility, like 'tail' in unix.

    exec('tail -3 /logs/reports/2017/02-15/173606-arachni-2415.log', $output);
    echo $output;
    
    // 2017-02-15 18:03:25 [*] Path Traversal: Analyzing response ...
    // 2017-02-15 18:03:27 [*] Path Traversal: Analyzing response ...
    // 2017-02-15 18:03:27 [*] Path Traversal: Analyzing response ...
    

提交回复
热议问题