小编MIk*_*eyy的帖子

如何在php中保留日志文件的最后n行数

我想删除旧日志文件中的所有行,并保留最底部的50行.

我该怎么做这样的事情,如果可能的话,我们可以改变这些线的方向,

normal input

111111
2222222
3333333
44444444
5555555

output like

555555
4444444
3333333
22222
111111
Run Code Online (Sandbox Code Playgroud)

要查看顶部的新鲜日志,仅查看50或100行.

如何加入这个?

// set source file name and path 
$source = "toi200686.txt"; 
// read raw text as array 
$raw = file($source) or die("Cannot read file"); 
// join remaining data into string 
$data = join('', $raw); 
// replace special characters with HTML entities 
// replace line breaks with <br />  
$html = nl2br(htmlspecialchars($data)); 
Run Code Online (Sandbox Code Playgroud)

它将输出作为HTML文件.那你的代码将如何运行呢?

php logging lines

0
推荐指数
1
解决办法
1941
查看次数

标签 统计

lines ×1

logging ×1

php ×1