我有一个CSV文件扫描结果。我只想阅读第一列并阅读第6行的行。
这就是我的尝试:
<html>
<body>
<h1>MAC Address have been verified</h1>
<table width="50%" border="1">
<tr>
<th>NO</th>
<th>MAC Address</th>
</tr>
<?php
if (($handle = fopen("data.csv", "r")) !== FALSE) {
$row = 1;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
echo "<tr>";
echo "<td><center>".$row++."</center></td>";
echo "<td>".$data[0]."</td>";
echo "</tr>";
} //end while
fclose($handle);
} //end if
?>
</table>
</body>enter code here
</html>
答案 0 :(得分:0)
以下重要的一行是 if($ row&gt; 6)break;
<?php
$row = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ( $row > 6 ) break;
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
}
}
fclose($handle);
}
?>