我目前正在使用以下 PHP 代码从 .htm 文件返回和格式化输出:
<?php
$es = "</span>";
$lines = file("http://www.example.com/log.htm", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($lines as $line){
list($date, $nick, $message) = explode(" ", $line, 3);
$str = substr($nick, 4, 1);
if($str=="+"){
$nickspan = '<span style="color:teal">';
$nick = substr_replace($nick, "", 2, 2);
echo("$date $nickspan$nick$es $message <br/>
");
} else {
if($str=="@"){
$nickspan = '<span style="color:#F20707">';
$nick = substr_replace($nick, "", 2, 2);
echo("$date $nickspan$nick$es $message <br/>
");
} else {
$str = substr($nick, 3, 1);
if($str=="*"){
$nickspan = '<span style="color:purple">';
$nick = substr_replace($nick, "", 1, 2);
echo("$date $nickspan$nick $message$es <br/>
");
} else {
$nickspan = '<span style="color:grey">';
$str = substr($nick, 2, 2);
if($str=="03"){
$nick = substr_replace($nick, "", 2, 2);
}
echo("$date $nickspan$nick$es $message <br/>
");
} } } }
?>
我如何将其更改为仅显示最后 50 行,而不是绝对列出本质上是日志文件的所有内容?