Detailed explanation of the solution to garbled Excel exported by PHP_PHP Tutorial

WBOY
Release: 2016-07-15 13:33:08
Original
901 people have browsed it

There are two main processes when we use

PHP to export Excel files:

1. Define the file name

2. Filling Excel data

In these two processes, there may be some garbled problems when exporting Excel from PHP. Let me talk about the solution below:

Solving the garbled file name exported by PHP to Excel:

Reason for garbled code: The Chinese version of Windows system platform used by the customer, and the file name encoding of the Windows platform is gb2312 (gbk), and our web page encoding generally uses utf-8 (internationalization) encoding in order to follow the existing trend. , then when we: header("Content-Disposition: inline; filename="" . $filename . ".xls""), garbled characters will appear. If your web page encoding is gb2312, then there is no need to consider encoding issues.

Solution: To transcode $filename, execute: iconv('utf-8", "gb2312", $filename). If your environment does not support the iconv function, you can replace it with another function, as long as you can Just convert the encoding of $filename to gbk.
But this problem will arise again, and Linux users will have garbled file names (because the file name on the Linux platform is not gbk encoded).

Considering this problem, I Use two methods: First: Give up some customers, after all, Windows system users account for the majority. Second: Like gmail, provide two download addresses, one with gbk encoding and one with utf-8 encoding.

Solution to Excel garbled code when PHP exports data in Excel:

PHP exported Excel garbled code Reason: Web page encoding and Excel encoding are inconsistent

Solution: Since the encoding is inconsistent, make it consistent. It's OK. Define Excel's character set: header("Content-Type: application/vnd.ms-excel; charset=UTF-8"). See charset=UTF-8 and let it match your web page encoding. The problem of garbled data in Excel can be solved by matching it. This is relatively simple!


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446093.htmlTechArticleWe have two main processes when using PHP to export Excel files: 1. Define the file name 2. Fill in Excel There may be some garbled problems when exporting data from PHP to Excel, as follows...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!