johnlemon
johnlemon

Reputation: 21509

How can import an UTF8 and ISO-8859-1 csv file?

I have an upload input on a site. Users can upload csv files with UTF8 or ISO-8859-1 or other encodings.

How can I correctly detect the encoding, convert it to UTF-8 so I can store it inside an UTF-8 DB ?

Upvotes: 1

Views: 2434

Answers (1)

Hikaru-Shindo
Hikaru-Shindo

Reputation: 1901

Have a look at Iconv and mb_detect_encoding().

There is no 100% safe way to determine the correct chatset, as long as there are no more information then the file itself. If you can be sure it's only these two character sets it should be safe through.

Upvotes: 1

Related Questions