$limit = 1;
$fileHandle = fopen($inputFileName, "r");
if ($fileHandle === FALSE) {
die('Error opening ' . $inputFileName);
}
// Set up a variable to hold our current position in the file
$offset = 0;
while (!feof($fileHandle)) {
// Go to where we were when we ended the last batch
fseek($fileHandle, $offset);
$i = 0;
while (($currRow = fgetcsv($fileHandle)) !== FALSE) {
$i++;
$row = implode('|', $currRow);
$list = explode('|', $row);
if (trim($list[0]) == 'System Setup') {
$fdt = $list[1];
$prvxdt = date('Y-m-d H:i:s', strtotime($fdt));
} elseif (trim($list[0]) == 'Probe Card Serial Number:') {
$prvxbc = substr(trim($list[1]), 0, 10);
}elseif (trim($list[0]) == 'Probe ID') {
$dia = substr(trim($list[23]), 0, 23);
}
if($i >= $limit)
{
//Update our current position in the file
$offset = ftell($fileHandle);
//Break out of the row processing loop
break;
}
}
}
// Close the file
fclose($fileHandle);
$fext = '.csv';
我想从 csv 文件中获取值,列名称称为直径 (um)。我已经通过这一行获取了列名称
elseif (trim($list[0]) == 'Probe ID') { $dia = substr(trim($list[23]), 0, 23); }
。
我想要直径 (um) 列中的总最大值和最小值。 如果我正确理解你的问题,你提到的列是 $list[23]
要获取最小值和最大值,您可以在 while 循环之前添加以下内容:
$maxx=0;
$minx=0;
然后在
$dia = substr(trim($list[23]), 0, 23);
行后面添加以下行
所以改变
$dia = substr(trim($list[23]), 0, 23);
到
$dia = substr(trim($list[23]), 0, 23);
if ($dia < $maxx) { $maxx=$dia; }
if ($dia > $minx) { $minx=$dia; }
while循环后,$maxx和$minx将分别为最大值和最小值