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
php csv
|
show 4 more comments
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
php csv
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
usehtmlspecialchars($cell, ENT_IGNORE)
instead ofhtmlspecialchars($cell)
.
– Mohammad Zare Moghadam
14 hours ago
Got the same result with htmlspecialchars($cell, ENT_IGNORE)
– ShakyIpsen
14 hours ago
Maybehtmlspecialchars($cell, ENT_SUBSTITUTE)
?
– Svenmarim
14 hours ago
|
show 4 more comments
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
php csv
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
php csv
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
usehtmlspecialchars($cell, ENT_IGNORE)
instead ofhtmlspecialchars($cell)
.
– Mohammad Zare Moghadam
14 hours ago
Got the same result with htmlspecialchars($cell, ENT_IGNORE)
– ShakyIpsen
14 hours ago
Maybehtmlspecialchars($cell, ENT_SUBSTITUTE)
?
– Svenmarim
14 hours ago
|
show 4 more comments
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
usehtmlspecialchars($cell, ENT_IGNORE)
instead ofhtmlspecialchars($cell)
.
– Mohammad Zare Moghadam
14 hours ago
Got the same result with htmlspecialchars($cell, ENT_IGNORE)
– ShakyIpsen
14 hours ago
Maybehtmlspecialchars($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
|
show 4 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 ofhtmlspecialchars($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