PHP export CSV file garbled related problem solving method

Source: Internet
Author: User
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!

  • 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.