G
G
Grigory Vasilkov2016-06-28 22:41:07
PHP
Grigory Vasilkov, 2016-06-28 22:41:07

How to cast attached file to UTF-8 via PHP?

The file below is an example given by google contacts for export. Such contacts are transferred in two clicks from phone to phone.
In fact, it looks like a regular CSV file.
When I opened it with the help of Chrome, Chrome said that it was CP1252 encoding.
Trying to convert it with an ICONV file turned into the ultimate mess.
Who did?
In this case, I do not know in advance what encoding of the input file, but I would like to work with UTF-8 without manual conversions - I uploaded the file, ran the script, and got the output file.
Example file: https://yadi.sk/d/3qr3MUmJsrqrr
I do it like this:

// get file
$content = file_get_contents($filename);
$content = mb_convert_encoding($content, 'UTF-8', 'CP1252');

UPDATED
Made mb_detect_encoding for everything I found.
Defined as ISO-8859-1.
Direct conversion with two known encodings still results in bugs.
UPDATED2
The roof just left. Half of the file is in ISO and half is in UTF-8!!!
Google shows us samples of quality, beauty and elegance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2016-06-28
@gzhegow

File in UTF-16LE.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question