Hi i have this csv file reader. I have this problem tho, it makes blank cells when it has some special characters like, "ø" "," "-". there might be more. Here is my code:
<?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>';
}
This is how it is shown when i try show the file. I will use the | to indicate cells and write "Blank" when it shows a blank cell
|Name|Datum|Property|Criterion|Type|Nominal|Actual|Tol-|Tol+|Dev|
|1)Height|Blank|Blank|Blank|inp|Blank|Blank|Blank|Blank|Blank|
How it should look:
|Name|Datum|Property|Criterion|Type|Nominal|Actual|Tol-|Tol+|Dev|
|1)Height|Blank|Ø|Blank|inp|123,3|123,3|-1|1|-0,24|
Hope this makes sense to you