我想使用 php 以 html 表格形式显示我的日志文件数据。我的日志文件数据看起来像
2019-08-01 07:45:13 112.196.23.170 Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0 42112452 并且用户点击了这封电子邮件:mike@jvpsus.com India IN Punjab
我想在表格行中显示2019-08-01 07:45:13
然后是第二行的112.196.23.170
然后显示整个Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0
然后 id 42112452第 4 行
然后第六行和用户点击了这封电子邮件:mike@jvpsus.com
最后第七排印度旁遮普邦
每当我试图获取数组中的数据时,在 foreach 数组分解为键和值之后。我试图用空间爆炸 (' ', $string)。但是整个句子字符与空间进入单独的数组索引。
当我尝试 foreach 时,它给了我这个输出
我想要的输出如下
这是我的代码
$logFile = 'testlog.log';
$lines = file($logFile); // Get each line of the file and store it as an array
// echo "<pre>";
// print_r($lines);
foreach($lines as $line)
{
// list($date, $time, $ip, $domain,$no,$mail,$cnt, $cod, $state) = explode(' ', $line);
$output = preg_replace('!\s+!', ' ', $line);
echo "<pre>";
print_r (explode(" ",$output));
}
?>```
当年话下
ibeautiful