Php export csv file garbled problem solution to this problem first let's talk about what is CSV file? CommaSeparatorValue (comma-separated values) is also. Intermediate files are often used for data conversion. for example, exporting data from Mysql to CSV files and exporting csv files through php. how can this problem be solved?
Php export csv file garbled problem solution
What is a CSV file first? Comma Separator Value (Comma-separated values) is also. An intermediate file is often used for data conversion, for example, exporting data from Mysql to CSV and importing CSV to SqlServer. In Linux, use a PHP script to export table data from a Mysql database to a csv file according to the conditions, and use UTF-8 encoding to export the CSV file, after opening the file, the Chinese characters in it become garbled characters (CSV files in Windows are associated with Microsoft Excel by default). It can be opened normally with Notepad ++ or Word, but the layout is messy. Cause: BOM and Microsoft.
What is BOM? Byte Order Mark (bid) is also.
To identify Unicode files, Microsoft recommends that all Unicode files start with zero width nobreak space. This is used as a "feature" or "byte-order mark (BOM) to identify the encoding and byte order (big-endian or little-endian) used in the file. the specific relationship is shown in the table below.
?
BytesEncoding Form
| 00 00 FE FF |
UTF-32, big-endian |
| Ff fe 00 00 |
UTF-32, little-endian. |
| FE FF |
UTF-16, big-endian |
| FF FE |
UTF-16, little-endian. |
| EF BB BF |
UTF-8 |
?
BOM is not used in Unix-like systems because it breaks the syntax conventions of existing ASCII files.
Implementation code if
Note: When writing a csv file, make sure that the php source code is UTF-8 without BOM and no content is output.
BOM is actually annoying. if your webpage (*. html) has a BOM, open it under IE6.x and you will find a magical blank line, but not under Firefox.
?
Source: http://www.i-felix.cn/blog/phpdao-chu-csvwen-jian-luan-ma-wen-ti-jie-jue-fang-fa-gai-si-de-wei-ruan
?
?
Xiaoshenge 2012-09-03 on the first floor learned how to convert the code. in the past, I only needed to switch the code. there was still a simple method. On the second floor, Tiandeng 2012-09-05 is correct. sometimes the code conversion is impractical!