Home > Backend Development > PHP Tutorial > Solve the problem of garbled characters in CSV files exported by PHP (graphics and text)

Solve the problem of garbled characters in CSV files exported by PHP (graphics and text)

WBOY
Release: 2016-07-25 09:04:24
Original
1023 people have browsed it
CSV file Comma Separator Value (comma separated values). Intermediate files commonly used for data conversion exist, such as exporting data from Mysql to CSV and importing CSV into SqlServer.

CSV file Comma Separator Value. Intermediate files commonly used for data conversion exist, such as exporting data from Mysql to CSV and importing CSV into SqlServer.

In the Linux environment, PHP exports the table data from the MySQL database into csv according to conditions, and uses UTF-8 encoding to export the CSV file. After opening, the Chinese becomes garbled (CSV files under Windows are associated with Microsoft Excel by default), use Notepad++ or Word It opens normally, but the layout is messy. The reason is: BOM.

What is BOM? Byte Order Mark.

In order to recognize Unicode files, Microsoft recommends that all Unicode files should start with ZERO WIDTH NOBREAK SPACE characters. This serves as a "signature" or "byte-order mark (BOM)" to identify the encoding and byte order (big-endian or little-endian) used in the file. The specific correspondence is shown in the table below . Solve the problem of garbled characters in CSV files exported by PHP (graphics and text) BOMs are not used in Unix-like systems because they break existing ASCII file syntax conventions.

Code: Solve the problem of garbled characters in CSV files exported by PHP (graphics and text)

Note: When writing the csv file, ensure that the PHP source code is utf-8, has no BOM, and does not output anything. The webpage (*.html) has a BOM, and a magical blank line will appear when opened under IE6.x. This strange phenomenon does not exist in Firefox.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template