PHP .CSV File reader blank spaces











up vote
0
down vote

favorite












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










share|improve this question
























  • please share some example data, and outputs of that data
    – Vad.Gut
    14 hours ago












  • ill update the question, with an example of how is is and how it should be
    – ShakyIpsen
    14 hours ago










  • use htmlspecialchars($cell, ENT_IGNORE) instead of htmlspecialchars($cell).
    – Mohammad Zare Moghadam
    14 hours ago










  • Got the same result with htmlspecialchars($cell, ENT_IGNORE)
    – ShakyIpsen
    14 hours ago










  • Maybe htmlspecialchars($cell, ENT_SUBSTITUTE) ?
    – Svenmarim
    14 hours ago

















up vote
0
down vote

favorite












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










share|improve this question
























  • please share some example data, and outputs of that data
    – Vad.Gut
    14 hours ago












  • ill update the question, with an example of how is is and how it should be
    – ShakyIpsen
    14 hours ago










  • use htmlspecialchars($cell, ENT_IGNORE) instead of htmlspecialchars($cell).
    – Mohammad Zare Moghadam
    14 hours ago










  • Got the same result with htmlspecialchars($cell, ENT_IGNORE)
    – ShakyIpsen
    14 hours ago










  • Maybe htmlspecialchars($cell, ENT_SUBSTITUTE) ?
    – Svenmarim
    14 hours ago















up vote
0
down vote

favorite









up vote
0
down vote

favorite











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










share|improve this question















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







php csv






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 14 hours ago

























asked 14 hours ago









ShakyIpsen

13




13












  • please share some example data, and outputs of that data
    – Vad.Gut
    14 hours ago












  • ill update the question, with an example of how is is and how it should be
    – ShakyIpsen
    14 hours ago










  • use htmlspecialchars($cell, ENT_IGNORE) instead of htmlspecialchars($cell).
    – Mohammad Zare Moghadam
    14 hours ago










  • Got the same result with htmlspecialchars($cell, ENT_IGNORE)
    – ShakyIpsen
    14 hours ago










  • Maybe htmlspecialchars($cell, ENT_SUBSTITUTE) ?
    – Svenmarim
    14 hours ago




















  • please share some example data, and outputs of that data
    – Vad.Gut
    14 hours ago












  • ill update the question, with an example of how is is and how it should be
    – ShakyIpsen
    14 hours ago










  • use htmlspecialchars($cell, ENT_IGNORE) instead of htmlspecialchars($cell).
    – Mohammad Zare Moghadam
    14 hours ago










  • Got the same result with htmlspecialchars($cell, ENT_IGNORE)
    – ShakyIpsen
    14 hours ago










  • Maybe htmlspecialchars($cell, ENT_SUBSTITUTE) ?
    – Svenmarim
    14 hours ago


















please share some example data, and outputs of that data
– Vad.Gut
14 hours ago






please share some example data, and outputs of that data
– Vad.Gut
14 hours ago














ill update the question, with an example of how is is and how it should be
– ShakyIpsen
14 hours ago




ill update the question, with an example of how is is and how it should be
– ShakyIpsen
14 hours ago












use htmlspecialchars($cell, ENT_IGNORE) instead of htmlspecialchars($cell).
– Mohammad Zare Moghadam
14 hours ago




use htmlspecialchars($cell, ENT_IGNORE) instead of htmlspecialchars($cell).
– Mohammad Zare Moghadam
14 hours ago












Got the same result with htmlspecialchars($cell, ENT_IGNORE)
– ShakyIpsen
14 hours ago




Got the same result with htmlspecialchars($cell, ENT_IGNORE)
– ShakyIpsen
14 hours ago












Maybe htmlspecialchars($cell, ENT_SUBSTITUTE) ?
– Svenmarim
14 hours ago






Maybe htmlspecialchars($cell, ENT_SUBSTITUTE) ?
– Svenmarim
14 hours ago



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371927%2fphp-csv-file-reader-blank-spaces%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371927%2fphp-csv-file-reader-blank-spaces%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]