thara Posted September 28, 2021 Share Posted September 28, 2021 In PHP, I am trying to create an array from a CSV file in this way. // CSV file: $csv = array_map('str_getcsv', file("{$uploadPath}/{$myFile}")); Of course it is working for me, but on thing I have to fixed. If I have non-English language characters in my CSV file, then those characters not showing correctly in PHP. That mean its showing question marks instead of showing original characters. This is the output of $csv array: Array ( [0] => Array ( [0] => SISP-0002 [1] => Harpic Floral 500ml [2] => ???????? ??????? 500ml [3] => 4792037107765 ) ) Can anybody tell me what would be the possible workaround to fix this issue. Quote Link to comment https://forums.phpfreaks.com/topic/313829-non-english-language-issue-in-creating-php-array-from-csv-file/ Share on other sites More sharing options...
Barand Posted September 28, 2021 Share Posted September 28, 2021 Have you specified a compatible charset for your page, such as UTF8? Quote Link to comment https://forums.phpfreaks.com/topic/313829-non-english-language-issue-in-creating-php-array-from-csv-file/#findComment-1590465 Share on other sites More sharing options...
thara Posted September 28, 2021 Author Share Posted September 28, 2021 7 minutes ago, Barand said: Have you specified a compatible charset for your page, such as UTF8? Yes Sir. I have set it inside page <head> tag as shown here. <meta charset="utf-8"> Do I need to set up a charset somewhere else to make it work, sir? Quote Link to comment https://forums.phpfreaks.com/topic/313829-non-english-language-issue-in-creating-php-array-from-csv-file/#findComment-1590467 Share on other sites More sharing options...
Barand Posted September 28, 2021 Share Posted September 28, 2021 Was the csv created using utf8? Quote Link to comment https://forums.phpfreaks.com/topic/313829-non-english-language-issue-in-creating-php-array-from-csv-file/#findComment-1590468 Share on other sites More sharing options...
thara Posted September 28, 2021 Author Share Posted September 28, 2021 20 minutes ago, Barand said: Have you specified a compatible charset for your page, such as UTF8? Sir, can you tell how I specified it on my page? <meta charset="utf-8"> Isn’t this how it was done? Quote Link to comment https://forums.phpfreaks.com/topic/313829-non-english-language-issue-in-creating-php-array-from-csv-file/#findComment-1590469 Share on other sites More sharing options...
Barand Posted September 28, 2021 Share Posted September 28, 2021 1 minute ago, thara said: <meta charset="utf-8"> Isn’t this how it was done? Yes, but what charset is the CSV? Also, does this apply to your setup (from str_getcsv in manual) Quote Note: The locale settings are taken into account by this function. If LC_CTYPE is e.g. en_US.UTF-8, strings in one-byte encodings may be read wrongly by this function. Quote Link to comment https://forums.phpfreaks.com/topic/313829-non-english-language-issue-in-creating-php-array-from-csv-file/#findComment-1590470 Share on other sites More sharing options...
thara Posted September 28, 2021 Author Share Posted September 28, 2021 (edited) Sir, This is how I set charset, when my CSV file is saved. Edited September 28, 2021 by thara Quote Link to comment https://forums.phpfreaks.com/topic/313829-non-english-language-issue-in-creating-php-array-from-csv-file/#findComment-1590471 Share on other sites More sharing options...
thara Posted September 28, 2021 Author Share Posted September 28, 2021 I created a CSV file using Google Sheets. Then it works. I see the problem with the CSV file that I created using Excel on my computer. Quote Link to comment https://forums.phpfreaks.com/topic/313829-non-english-language-issue-in-creating-php-array-from-csv-file/#findComment-1590474 Share on other sites More sharing options...
Barand Posted September 28, 2021 Share Posted September 28, 2021 What charset is the google one using? Quote Link to comment https://forums.phpfreaks.com/topic/313829-non-english-language-issue-in-creating-php-array-from-csv-file/#findComment-1590482 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.