PHP how can i get my csv table to show correctly?
Hi i have this problem that my code can't read my numbers correctly. the file im trying to read is a .csv file seperated by commas. any help is appreciated.
i havent been able to find anything that does exacly as i needed yet, it works if i replace the , with . but i need it to be , for my project.
<?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, ENT_COMPAT). '</td>';
}
echo '</tr>';
}
fclose($f);
echo'</tbody>';
echo '</table>';
}
the table Looks like in excel
https://gyazo.com/49e8b16d369b1fa61496601952ca953b
and here is how it looks on my site
https://gyazo.com/b271c3a221587b2e0c6b7ee4cebd6bdb
From what i have read, the reason i get these errors is because i need UTF-8, to be able to read my language
php csv
add a comment |
Hi i have this problem that my code can't read my numbers correctly. the file im trying to read is a .csv file seperated by commas. any help is appreciated.
i havent been able to find anything that does exacly as i needed yet, it works if i replace the , with . but i need it to be , for my project.
<?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, ENT_COMPAT). '</td>';
}
echo '</tr>';
}
fclose($f);
echo'</tbody>';
echo '</table>';
}
the table Looks like in excel
https://gyazo.com/49e8b16d369b1fa61496601952ca953b
and here is how it looks on my site
https://gyazo.com/b271c3a221587b2e0c6b7ee4cebd6bdb
From what i have read, the reason i get these errors is because i need UTF-8, to be able to read my language
php csv
add a comment |
Hi i have this problem that my code can't read my numbers correctly. the file im trying to read is a .csv file seperated by commas. any help is appreciated.
i havent been able to find anything that does exacly as i needed yet, it works if i replace the , with . but i need it to be , for my project.
<?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, ENT_COMPAT). '</td>';
}
echo '</tr>';
}
fclose($f);
echo'</tbody>';
echo '</table>';
}
the table Looks like in excel
https://gyazo.com/49e8b16d369b1fa61496601952ca953b
and here is how it looks on my site
https://gyazo.com/b271c3a221587b2e0c6b7ee4cebd6bdb
From what i have read, the reason i get these errors is because i need UTF-8, to be able to read my language
php csv
Hi i have this problem that my code can't read my numbers correctly. the file im trying to read is a .csv file seperated by commas. any help is appreciated.
i havent been able to find anything that does exacly as i needed yet, it works if i replace the , with . but i need it to be , for my project.
<?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, ENT_COMPAT). '</td>';
}
echo '</tr>';
}
fclose($f);
echo'</tbody>';
echo '</table>';
}
the table Looks like in excel
https://gyazo.com/49e8b16d369b1fa61496601952ca953b
and here is how it looks on my site
https://gyazo.com/b271c3a221587b2e0c6b7ee4cebd6bdb
From what i have read, the reason i get these errors is because i need UTF-8, to be able to read my language
php csv
php csv
asked Nov 21 at 7:00
ShakyIpsen
86
86
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I finally found the answer myself... after a long time of testing none stop, i found this answer
// 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, 1000, ";")) !== 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 ($line as $cell) {
echo '<td>' .htmlspecialchars($cell, ENT_COMPAT). '</td>';
}
echo '</tr>';
}
fclose($f);
echo'</tbody>';
echo '</table>';
}
hope someone could use this, what i have noticed with this solution is that, i think the while (($line = fgetcsv($f, 1000, ";")) !== false) {
. ive tested it and it could get over 10000 lines. Anyways what i found out saves someone some time. I for sure could have used it.
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
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%2f53406784%2fphp-how-can-i-get-my-csv-table-to-show-correctly%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I finally found the answer myself... after a long time of testing none stop, i found this answer
// 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, 1000, ";")) !== 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 ($line as $cell) {
echo '<td>' .htmlspecialchars($cell, ENT_COMPAT). '</td>';
}
echo '</tr>';
}
fclose($f);
echo'</tbody>';
echo '</table>';
}
hope someone could use this, what i have noticed with this solution is that, i think the while (($line = fgetcsv($f, 1000, ";")) !== false) {
. ive tested it and it could get over 10000 lines. Anyways what i found out saves someone some time. I for sure could have used it.
add a comment |
I finally found the answer myself... after a long time of testing none stop, i found this answer
// 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, 1000, ";")) !== 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 ($line as $cell) {
echo '<td>' .htmlspecialchars($cell, ENT_COMPAT). '</td>';
}
echo '</tr>';
}
fclose($f);
echo'</tbody>';
echo '</table>';
}
hope someone could use this, what i have noticed with this solution is that, i think the while (($line = fgetcsv($f, 1000, ";")) !== false) {
. ive tested it and it could get over 10000 lines. Anyways what i found out saves someone some time. I for sure could have used it.
add a comment |
I finally found the answer myself... after a long time of testing none stop, i found this answer
// 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, 1000, ";")) !== 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 ($line as $cell) {
echo '<td>' .htmlspecialchars($cell, ENT_COMPAT). '</td>';
}
echo '</tr>';
}
fclose($f);
echo'</tbody>';
echo '</table>';
}
hope someone could use this, what i have noticed with this solution is that, i think the while (($line = fgetcsv($f, 1000, ";")) !== false) {
. ive tested it and it could get over 10000 lines. Anyways what i found out saves someone some time. I for sure could have used it.
I finally found the answer myself... after a long time of testing none stop, i found this answer
// 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, 1000, ";")) !== 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 ($line as $cell) {
echo '<td>' .htmlspecialchars($cell, ENT_COMPAT). '</td>';
}
echo '</tr>';
}
fclose($f);
echo'</tbody>';
echo '</table>';
}
hope someone could use this, what i have noticed with this solution is that, i think the while (($line = fgetcsv($f, 1000, ";")) !== false) {
. ive tested it and it could get over 10000 lines. Anyways what i found out saves someone some time. I for sure could have used it.
answered Nov 21 at 9:54
ShakyIpsen
86
86
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f53406784%2fphp-how-can-i-get-my-csv-table-to-show-correctly%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