这是csv格式:
ServerA,OK,app1
ServerB,OK,app2
ServerC,OK,app3
ServerD,,app4
ServerA,OK,app2
ServerB,,app3
ServerC,OK,app1
ServerD,OK,app2
ServerA,OK,app3
ServerB,OK,app1
ServerC,,app2
我想要显示的是:
Server: App1: App2: App3: App4
ServerA OK OK OK OK
SERverB OK OK N/A OK
如果第二个字段为空,则显示 N/A。
这是我尝试过的:
$file = "serverdata.txt";
$fp = fopen($file, "r") or die("Can't open file serverdata.txt");
while(!feof($fp)) {
$data = fgets($fp, 1024);
$navData = explode(',',$data);
$host = $navData[0];
$app = $navData[2];
$status = $navData[1];
$myData[$host][$app] = $status;
}
foreach ($myData as $tempHost) {
if (isset($myData[$tempHost]['app1'])) {
$App1_status = $mydata[$tempHost]['app1'];
}
else {
$App1_status = "N/A";
}
.
.
.
.
<same for all other apps status >
print "<TD>$tempHost</TD><TD>$App1_status</TD><TD>$App2_status</TD><TD>$App3_status</TD> <TD>$App4_status</TD></TR>\n";
}
}
似乎没有得到它的工作,任何帮助将不胜感激。