How to export Excel garbled characters in PHP _ PHP Tutorial

Source: Internet
Author: User
Explains how to export Excel garbled characters in PHP. When using PHP to export an Excel file, there are two main processes: 1. defining the file name 2. filling in Excel data. some PHP Excel export garbled characters may occur. below we are using

There are two main processes for PHP to export an Excel file:

1. define the file name

2. fill in Excel data

Some PHP Excel export garbled characters may occur during these two processes. the solution is as follows:

Solve the Excel file export garbled by PHP:

Cause of garbled characters: the Chinese version of the Windows system platform used by the customer, while the file name encoding of the Windows platform is gb2312 (gbk). in order to follow up the existing trend, we generally use UTF-8 (international) encoding, in this case, when we: header ("Content-Disposition: inline; filename = "". $ filename. ". if your webpage code is gb2312, you do not need to consider encoding.

Solution: transcode $ filename and execute: iconv ('utf-8 "," gb2312 ", $ filename ). If your environment does not support iconv functions, you only need to convert $ filename encoding to gbk.
However, this problem occurs again, and linux users may encounter garbled file names (because the file name on the linux platform is not gbk encoded ).

To solve this problem, I adopt two methods: first, give up some customers. after all, windows users account for the majority. Second: like gmail, it provides two. A file name must be gbk encoded, and a file name must be UTF-8 encoded.

Solve the Excel data export garbled by PHP in Excel:

Reasons for PHP Excel export garbled characters: webpage encoding is inconsistent with Excel encoding.

Solution: Since the encoding is inconsistent, it is okay to make it consistent. Define the Excel character set: header ("Content-Type: application/vnd. ms-excel; charset = UTF-8 "), see charset = UTF-8, let it and your web page encoding consistent can solve the problem of data garbled in Excel, this is relatively simple!


PHP has two main processes for exporting Excel files: 1. defining the file name 2. filling in Excel data may cause some PHP Excel export garbled characters...

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.