显示数组最新读数的php代码
我有一个代码,它将以所附格式显示日志文件数据, 在这里,它将显示表中的所有读数 我只需要显示最近或最后一次阅读如何显示?请帮助我。我已在链接中附加了日志文件显示数组最新读数的php代码,php,Php,我有一个代码,它将以所附格式显示日志文件数据, 在这里,它将显示表中的所有读数 我只需要显示最近或最后一次阅读如何显示?请帮助我。我已在链接中附加了日志文件 在线实时温度和压力监测系统 表,th,td{ 边框:1px纯黑; 边界塌陷:塌陷; } th,td{ 填充物:5px; } 年 月 日期 时间 传感器ID 位置 压力(磅/平方英寸) 温度 仅显示该文件中的最后一行 计算该文件中的总行数, 迭代每一行,如果不是最后一行,则跳过该行。仅显示该文件中的最后一行 计算该文件中的总行数, 迭代每
在线实时温度和压力监测系统
表,th,td{
边框:1px纯黑;
边界塌陷:塌陷;
}
th,td{
填充物:5px;
}
年
月
日期
时间
传感器ID
位置
压力(磅/平方英寸)
温度
仅显示该文件中的最后一行
计算该文件中的总行数,
迭代每一行,如果不是最后一行,则跳过该行。仅显示该文件中的最后一行 计算该文件中的总行数,
迭代每一行,如果不是最后一行,则跳过该行。每次检测到27个字符时,代码都会重新分配
$data
,如果只想打印最后一组结果,只需将字符串分解(所有substr()
)和回显部分移到循环之外即可
无需关闭和重新打开零件之间的
和
标记
如果你需要的是最新的值,你应该考虑改写你的代码。自下而上阅读日志,一旦检测到包含27个字符的行,找到下一个包含23个字符的行,然后在分配的第一个实例中返回
$hello4
,以打破循环,这样更高效、更便于记忆
<meta http-equiv="refresh" content="10" >
<html>
<h1><center>Online Real Time Temperature and Pressure Monitoring System</center></h1>
<head>
<style>
table,th,td{
border:1px solid black;
border-collapse: collapse;
}
th,td{
padding: 5px;
}
</style>
</head>
<body>
<table align ="center" style="width:60%">
<tr>
<th>Year</th>
<th>Month</th>
<th>Date</th>
<th>Time</th>
<th>Sensor ID</th>
<th>Position</th>
<th>Pressure(psi)</th>
<th>Temperature</th>
</tr>
<?php
error_reporting(E_ALL & ~E_NOTICE);
$file_handle = fopen("temp.log", "rb");
while (!feof($file_handle) ) {
$line_of_text = fgets($file_handle);
$parts = explode(' ', $line_of_text);
$finalstr=$parts[0]."<BR>";
$hello=explode('>',end($parts));
$hello2=$hello[0]."<BR>";
$hello3=strlen($hello2);
if($hello3==23){
$timestamp=$hello2;
}
elseif($hello3==27)
{
$data=$hello2;
$hello4=explode('-',$timestamp."-".$data);
}
elseif ($hello3 == 50)
{
echo "";
}
}
fclose($file_handle);
$year = substr($hello4[0], 1, 4);
$Month = substr($hello4[0], 5, 2);
$Date = substr($hello4[0], 7, 2);
$Hour = substr($hello4[0], 9, 2);
$Min = substr($hello4[0], 11, 2);
$sec = substr($hello4[0], 13, 2);
$time = $Hour . ":" . $Min . ":" . $sec;
$sensorid1 = substr($hello4[1], 4, 2);
$sensorid2 = substr($hello4[1], 7, 2);
$Pressure1 = substr($hello4[1], 10, 2);
$Pressure2 = substr($hello4[1], 13, 2);
$temperature = substr($hello4[1], 16, 2);
$finalsensor = $sensorid1 . $sensorid2;
$finalPressure = $Pressure1 . $Pressure2;
$finalPressure1 = (hexdec($finalPressure) - 1531) / 100 + 0.61;
$finaltemperature1 = hexdec($temperature) - 40;
$position = "FL";
?>
<tr>
<td><center><?php
echo ($year); ?></center></td>
<td><center><?php
echo ($Month); ?></center></td>
<td><center><?php
echo ($Date); ?></center></td>
<td><center><?php
echo ($time); ?></center></td>
<td><center><?php
echo ($finalsensor); ?></center></td>
<td><center><?php
echo ($position); ?></center></td>
<td><center><?php
echo ($finalPressure1); ?></center></td>
<td><center><?php
echo ($finaltemperature1); ?></center></td>
</tr>
</body>
</html>
在线实时温度和压力监测系统
表,th,td{
边框:1px纯黑;
边界塌陷:塌陷;
}
th,td{
填充物:5px;
}
年
月
日期
时间
传感器ID
位置
压力(磅/平方英寸)
温度
每次检测到27个字符时,您的代码都会重新分配$data
,如果您只想打印最后一组结果,只需将字符串分解(所有substr()
)和回显部分移到循环之外即可
无需关闭和重新打开零件之间的
和
标记
如果你需要的是最新的值,你应该考虑改写你的代码。自下而上阅读日志,一旦检测到包含27个字符的行,找到下一个包含23个字符的行,然后在分配的第一个实例中返回
$hello4
,以打破循环,这样更高效、更便于记忆
<meta http-equiv="refresh" content="10" >
<html>
<h1><center>Online Real Time Temperature and Pressure Monitoring System</center></h1>
<head>
<style>
table,th,td{
border:1px solid black;
border-collapse: collapse;
}
th,td{
padding: 5px;
}
</style>
</head>
<body>
<table align ="center" style="width:60%">
<tr>
<th>Year</th>
<th>Month</th>
<th>Date</th>
<th>Time</th>
<th>Sensor ID</th>
<th>Position</th>
<th>Pressure(psi)</th>
<th>Temperature</th>
</tr>
<?php
error_reporting(E_ALL & ~E_NOTICE);
$file_handle = fopen("temp.log", "rb");
while (!feof($file_handle) ) {
$line_of_text = fgets($file_handle);
$parts = explode(' ', $line_of_text);
$finalstr=$parts[0]."<BR>";
$hello=explode('>',end($parts));
$hello2=$hello[0]."<BR>";
$hello3=strlen($hello2);
if($hello3==23){
$timestamp=$hello2;
}
elseif($hello3==27)
{
$data=$hello2;
$hello4=explode('-',$timestamp."-".$data);
}
elseif ($hello3 == 50)
{
echo "";
}
}
fclose($file_handle);
$year = substr($hello4[0], 1, 4);
$Month = substr($hello4[0], 5, 2);
$Date = substr($hello4[0], 7, 2);
$Hour = substr($hello4[0], 9, 2);
$Min = substr($hello4[0], 11, 2);
$sec = substr($hello4[0], 13, 2);
$time = $Hour . ":" . $Min . ":" . $sec;
$sensorid1 = substr($hello4[1], 4, 2);
$sensorid2 = substr($hello4[1], 7, 2);
$Pressure1 = substr($hello4[1], 10, 2);
$Pressure2 = substr($hello4[1], 13, 2);
$temperature = substr($hello4[1], 16, 2);
$finalsensor = $sensorid1 . $sensorid2;
$finalPressure = $Pressure1 . $Pressure2;
$finalPressure1 = (hexdec($finalPressure) - 1531) / 100 + 0.61;
$finaltemperature1 = hexdec($temperature) - 40;
$position = "FL";
?>
<tr>
<td><center><?php
echo ($year); ?></center></td>
<td><center><?php
echo ($Month); ?></center></td>
<td><center><?php
echo ($Date); ?></center></td>
<td><center><?php
echo ($time); ?></center></td>
<td><center><?php
echo ($finalsensor); ?></center></td>
<td><center><?php
echo ($position); ?></center></td>
<td><center><?php
echo ($finalPressure1); ?></center></td>
<td><center><?php
echo ($finaltemperature1); ?></center></td>
</tr>
</body>
</html>
在线实时温度和压力监测系统
表,th,td{
边框:1px纯黑;
边界塌陷:塌陷;
}
th,td{
填充物:5px;
}
年
月
日期
时间
传感器ID
位置
压力(磅/平方英寸)
温度
您的链接显示一个404,但假设每一行都包含一条新记录,这可能是您正在查找的链接显示404错误,但在左上角,您可以找到下载文件的下载选项,我看到了您发布的链接,但是文件中的数据记录有很多不需要的数据,我会在代码中过滤,我只需要过滤数据。链接的可能副本显示404,但假设每行包含一条新记录,这可能是你正在寻找的链接显示404错误,但在左上角你可以找到下载选项,下载文件,我看到了你发布的链接,但是文件中的数据记录有很多不需要的数据,我将在代码中过滤这些数据,我只需要过滤数据。每行可能重复显示为单独的数组,因此每行显示1行的计数每行显示为单独的数组,因此每行显示1行的计数很高兴能提供帮助,但请学习使用trim()和strpos(),您正在徒劳地创建不必要的进程和阵列。您不需要使用单个explode()。很高兴能提供帮助,但请学习使用trim()和strpos(),您是在徒劳地创建不必要的进程和阵列。您不需要为此使用单个explode()。