PHP - Returning the last line in a file?

后端 未结 9 1549
鱼传尺愫
鱼传尺愫 2020-11-30 09:46

I\'m guessing it\'s fgets, but I can\'t find the specific syntax. I\'m trying to read out (in a string I\'m thinking is easier) the last line added to a log file.

9条回答
  •  被撕碎了的回忆
    2020-11-30 10:40

    If you want to read a file line by line the file function reads the contents of a file, line by line and returns each line as an element of an array.

    So you could do something simple like:

    $lines    = file('log.txt');
    $lastLine = array_pop($lines);
    

提交回复
热议问题