2016-06-22 1 views
1

ログファイルのデータを添付の形式で表示するコードがあります ここにはすべての値がテーブルに表示されます 最新のものか最後のものかを表示する必要がありますそれを表示する方法を読む?me.Iは、そのファイル内のリンク Log File最新の配列を表示するためのPHPコード

<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> 
</body> 
</html> 
<?PHP 
error_reporting(E_ALL & ~E_NOTICE); 
$file_handle = fopen("D:/192.168.1.12_10000-gprs20160525.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); 
$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"; 

?> 
<html> 
<head> 

</head> 
<body> 

    <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> 
    <?php 
    } 
    elseif($hello3==50) 
    { 
    echo ""; 
    } 
    } 
    fclose($file_handle); 

    ?> 
+0

あなたのリンク404を示しているが、各ラインを想定すると、新しいレコードが含まれている、これはあなたがhttp://stackoverflow.com/questions/1510141/read-last-line-from-file探しているものかもしれ – SML

+0

リンクで404エラーが表示されますが、左上にファイルをダウンロードするダウンロードオプションがあります。 –

+0

あなたが投稿したリンクを見ましたが、ファイルに記録されているデータには、コード内でフィルタリングされたデータのみが必要 –

答えて

0

あなたは結果のちょうど最後のセットを印刷したい場合は、単に文字列の分解(すべてsubstr())を移動し、whileループの外の部分をエコー。

<html>タグと<body>タグを閉じて再度開く必要はありません。

最新の値が必要な場合は、コードの書き換えを検討する必要があります。 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> 
+0

ワウその作業!!!!!!あなたの提案をありがとう!!!! –

+0

喜んで役立つが、trim()とstrpos()を使うことを覚えていれば、不要なプロセスや配列を何も作成していない。これには単一のexplode()を使う必要はありません。 – SML

0

のみを表示し、最後の行にログファイルを添付している助けてください。

そのファイルの合計行を計算します。 各行を繰り返し、最後の行でない場合はその行をスキップします。あなたのコードの再割り当て$data毎回27の文字が検出され

+0

各行別々の配列として表示各行がcounを表示するように1ラインのt –

関連する問題