嗨,我有这个csv文件阅读器。我有这个问题,当它有一些特殊字符,例如“ø”,“-”时,它会生成空白单元格。可能还有更多。这是我的代码:
<?php
// inkludere vores footer hvis logget ind
if ($user->is_loggedin() == true) {
// File selector
$path = "./assets/csv";
$latest_ctime = 0;
$latest_filename = '';
$d = dir($path);
while (false !== ($entry = $d->read())) {
$filepath = "{$path}/{$entry}";
// could do also other checks than just checking whether the entry is a file
if (is_file($filepath) && filectime($filepath) > $latest_ctime) {
$latest_ctime = filectime($filepath);
$latest_filename = $entry;
}
}
// table start
echo'<h1 class="text-center">CSV Table</h1>';
echo'<h6 class="text-center">'.$latest_filename.'</h6>';
echo '<table id="example" class=" table table-striped table-bordered" style="width:100%">';
echo'<tbody>';
$f = fopen("$path/$latest_filename", "r");
while (($line = fgetcsv($f)) !== false) {
$row = $line[0]; // We need to get the actual row (it is the first element in a 1-element array)
$cells = explode(";",$row);
echo '<tr>';
foreach ($cells as $cell) {
echo '<td>' . htmlspecialchars($cell) . '</td>';
}
echo '</tr>';
}
fclose($f);
echo'</tbody>';
echo '</table>';
}
这是我尝试显示文件时的显示方式。 我将使用|指示单元格并在显示空白单元格时写“空白”
|名称|基准|属性|标准|类型|名义|实际| Tol- | Tol + | Dev |
| 1)高度|空白|空白|空白|空白| inp |空白|空白|空白|空白|空白|空白|
外观如何:
|名称|基准|属性|标准|类型|名义|实际| Tol- | Tol + | Dev |
| 1)高度|空白|Ø|空白| inp | 123,3 | 123,3 | -1 | 1 | -0,24 |
希望这对您有意义