AndieB Posted June 22, 2009 Share Posted June 22, 2009 Hi all, I'm going to load a CSV file and then take the data and do a MySQL insertion. Of course, that is just to import with MySQL, but I need to do some testing of the data first, in order to see into what table the data should be put. Positive values will go into one table and negative values into another. Now, the CSV file I've got, is in UTF-8 charset. When testing this simple code: <?php $row = 1; $handle = fopen("finance.csv", "r"); while (($data = fgetcsv($handle, 0, ";")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />\n"; } } fclose($handle); ?> I get a problem. It does not show the data correctly. I've modified the script to look like this: <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> </head> <body> <?php $row = 1; $handle = fopen("finance.csv", "r"); while (($data = fgetcsv($handle, 0, ";")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />\n"; } } fclose($handle); ?> </body> </html> But that did not help at all. What am I doing wrong? How should I make sure that the CHARSET becomes correct? Thank you for any kind of help! --Andreas Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted June 22, 2009 Share Posted June 22, 2009 you can try setting the locale setlocale(LC_ALL, 'en_US.UTF-8'); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.