I'm trying to read shift jis win csv mixed with Chinese and Japanese as below in php, but only Chinese is translated, how can I read it with utf-8?
[FYI] csv itself has to be saved as shift jis win due to project reasons, so I want to convert shift jis win->utf-8.
■ csv hex dump
■ Outputphp csv shift-jis locale
Why don't you put a BOM on the CSV?
Shift_JIS (and CP932, which includes extensions by MS) does not contain Chinese characters such as 」, 」, and 」.Therefore, there is no Shift_JIS CSV file containing at least these characters.
As far as the hexadecimal dump is concerned, all characters that cannot be represented as Shift_JIS have been converted to literal
?(3f) at the CSV stage, and the original Chinese information has already been lost.So you'll need to rethink how to save it to CSV.
The reason why CSVs need to be saved and they are tied to Shift_JIS is that most of them want to view/check CSVs stored in Excel.Excel can read UTF-8 CSV files correctly only if a BOM is granted.
The code above is a PHP copy of that Excel habit.Make the input code compatible with UTF-8 with BOM so that you can read the existing Shift_JIS CSV for compatibility.
© 2022 OneMinuteCode. All rights reserved.