Jump to content

non-English language issue in creating php array from CSV file


thara

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.