Solve the problem of php exporting csv file garbled characters (text)

Source: Internet
Author: User
Solve the problem of php exporting csv file garbled characters (text)
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 to SqlServer.

CSV fileComma Separator Value (Comma-separated values ). Intermediate files commonly used for data conversion exist, such as exporting data from Mysql to CSV and importing CSV to SqlServer.

In linux, php exports table data from the mysql database to csv according to the conditions, and uses UTF-8 encoding to export CSV files, after opening the file, Chinese characters are garbled (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. The reason is: BOM.

What is BOM?? Byte Order Mark (bid ).

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. BOM is not used in Unix-like systems because it breaks the syntax conventions of existing ASCII files.

Code:

Note: When writing a csv file, make sure that the php source code is UTF-8 without BOM and no content is output. If a webpage (*. html) has a BOM, a magical blank line will appear when it is opened under IE6.x, which is not found in Firefox.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.