Detailed explanation of PHP export Excel garbled solution _php Tutorial

Source: Internet
Author: User
We are using

PHP has two main processes for exporting Excel files:

1. Define file name

2. Populate Excel data

These two processes may appear some PHP export Excel garbled problem, below I say the solution:

Resolve file name of PHP export Excel garbled:

Garbled reason: The customer uses the Chinese version of the Windows System platform, and the Windows platform file name encoding gb2312 (GBK), and our web page encoding in order to follow the current trend is generally used utf-8 (internationalization) coding, when we: header (" Content-disposition:inline; Filename= "". $filename. ". xls") will appear garbled, if your Web page encoding is gb2312 that does not have to consider the coding problem.

Workaround: For $filename transcoding, execute: Iconv (' Utf-8 ', "gb2312", $filename). If your environment does not support the ICONV function can be replaced by other functions, as long as the $filename encoding can be converted to GBK on the line.
But this problem will come again, Linux users will appear garbled file name (because the Linux platform file name is not GBK encoding).

In view of this problem I use two ways: first: Give up some customers, after all, Windows system users accounted for the majority. Second: Like Gmail, two download addresses are available. A filename GBK encoded, a filename utf-8 encoded.

Troubleshoot PHP export of Excel data in Excel garbled:

PHP Export Excel garbled reason: page encoding and Excel encoding inconsistent.

WORKAROUND: Since the coding is inconsistent, it is OK to make it consistent. Defines the character set for Excel: Header ("Content-type:application/vnd.ms-excel; Charset=utf-8 "), see Charset=utf-8, let it and your page encoding consistent can solve the problem of data garbled in Excel, this is relatively simple!


http://www.bkjia.com/PHPjc/446093.html www.bkjia.com true http://www.bkjia.com/PHPjc/446093.html techarticle when we use PHP to export Excel files There are two main procedures: 1, the definition of file name 2, populate the Excel data in the two processes may appear some PHP exported Excel garbled problem, the following ...

  • Related Article

    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.