PHP Export CSV file garbled problem solving method
PHP Export CSV file garbled problem solving method
Before you say this question, what is a CSV file first? Comma Separator Value (comma separated value) is also. Intermediate files that are often used for data conversion exist, such as exporting data from MySQL to CSV and importing CSV into SQL Server. In Linux under the PHP script from the MySQL database to export the table data to CSV, using UTF-8 encoding export CSV file, open the inside of the Chinese became garbled (Windows CSV file by default associated with Microsoft Excel), Use notepad++ or Word to open the normal, but the layout is very messy. Reason: BOM trouble, Microsoft caused the curse.
What is a BOM? The Byte order mark (bit-order mark) is also.
To identify Unicode files, Microsoft recommends that all Unicode files begin with the ZERO WIDTH nobreak space character. This is known as a "signature" or "byte order mark (Byte-order Mark,bom)" To identify the encoding and byte order (Big-endian or Little-endian) used in the file, as described in the following table.
?
Bytesencoding Form
XX-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 |
?
The BOM is not used in Unix-like systems because it destroys 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, and that there is no BOM, and that no content is output.
BOM is really annoying, if your Web page (*.html) has a BOM, open under ie6.x will find a magical empty line, Firefox is not
?
Source: Http://www.i-felix.cn/blog/phpdao-chu-csvwen-jian-luan-ma-wen-ti-jie-jue-fang-fa-gai-si-de-wei-ruan
?
?
1/F Xiaoshenge 2012-09-03
Study, previously only know the need to convert the code, there is a simple method.
2 Floor Ladder Dream 2012-09-05
Yes, transcoding is sometimes impractical!