


Summary of solutions to Chinese garbled Chinese characters exported by PHP_PHP Tutorial
My page is encoded in UTF-8. What should I do to ensure that the exported excel will not be garbled? And because different operating systems have different system encodings, do they have to provide files in different encoding formats for download?
1. Define file name
2. Fill in Excel data
There may be some garbled problems when exporting Excel from PHP during these two processes. Let me talk about the solution below:
Solve the garbled Excel exported by PHP of data in Excel:
The reason why PHP exports Excel with garbled characters: The web page encoding is inconsistent with the Excel encoding.
Solution: Since the encoding is inconsistent, it will be OK to make it consistent. Define Excel’s character set:
代码如下 | 复制代码 |
header(“Content-Type: application/vnd.ms-excel; charset=UTF-8″) |
, you see charset=UTF-8, make it consistent with your web page encoding to solve the problem of garbled data in Excel, this is relatively simple!
Attached is a php export Excel class
The code is as follows | Copy code | ||||||||||||||||||||||||
* * To change the template for this generated file go to
|
The code is as follows | Copy code |
iconv("UTF-8", "GBK", $value); |
Other methods
Finally, I adopted the method of phpMyAdmin. I used HTMLExcel. We are familiar with HTML and the format is as follows.
The code is as follows | Copy code | ||||||||||||||||||||
|
The code is as follows | Copy code | ||||
header("Content-type:application/vnd .ms-excel");
|
. If your environment does not support the iconv function, you can use another function, as long as the encoding of $filename can be converted to gbk.
But this problem will arise again, and Linux users will have garbled file names (because the Linux platform file names are not gbk encoded).
Considering this problem, I adopted two methods: First: give up some customers, after all, Windows system users account for the majority. Second: Like gmail, two download addresses are provided. One file name is gbk encoded, and one file name is utf-8 encoded.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

As a world-renowned sports brand, Nike's shoes have attracted much attention. However, there are also a large number of counterfeit products on the market, including fake Nike shoe boxes. Distinguishing genuine shoe boxes from fake ones is crucial to protecting the rights and interests of consumers. This article will provide you with some simple and effective methods to help you distinguish between real and fake shoe boxes. 1: Outer packaging title By observing the outer packaging of Nike shoe boxes, you can find many subtle differences. Genuine Nike shoe boxes usually have high-quality paper materials that are smooth to the touch and have no obvious pungent smell. The fonts and logos on authentic shoe boxes are usually clear and detailed, and there are no blurs or color inconsistencies. 2: LOGO hot stamping title. The LOGO on Nike shoe boxes is usually hot stamping. The hot stamping part on the genuine shoe box will show
