search
HomeBackend DevelopmentPHP ProblemWhat to do if php excel exports garbled characters

php Excel export garbled solution: 1. Convert "$filename" and execute the statement "iconv('utf-8", "gb2312", $filename)"; 2. Define Excel characters The set is "charset=UTF-8".

What to do if php excel exports garbled characters

Recommended: "PHP Video Tutorial"

Php export Excel Solving garbled files

There are two main processes when exporting Excel files with Php:

1. Define the file name

2. Fill in the Excel data

There may be some garbled characters in these two processes. Let me talk about the solution below:

Solving the garbled characters in the file name:

Cause of garbled characters: The Chinese version of Windows system platform used by the customer, 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. At this time, 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 the encoding problem.

Solution: transcode $filename, Execution: iconv('utf-8", "gb2312", $filename). 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 come again, and Linux users will have garbled file names (because the file names on the Linux platform are not gbk encoded).

Considering this problem, I adopted two methods: First: give up some customers, after all, Windows system users account for the vast majority. Second: Like gmail, two download addresses are provided. One file name is gbk encoded, and one file name is utf-8 encoded.

Solution to garbled data in Excel:

Cause of garbled code: 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 will see charset=UTF-8. Make it consistent with your web page encoding to solve Excel problem. The internal data is garbled. This is relatively simple!

The above is the detailed content of What to do if php excel exports garbled characters. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
一文教会你Excel折叠表格分类汇总功能一文教会你Excel折叠表格分类汇总功能May 12, 2022 am 11:58 AM

本篇文章给大家带来了关于excel的相关知识,其中主要介绍了关于折叠表格的相关问题,就是分类汇总的功能,这样查看数据会非常的方便,下面一起来看一下,希望对大家有帮助。

实用Excel技巧分享:计算年数差、月数差、周数差实用Excel技巧分享:计算年数差、月数差、周数差Apr 22, 2022 am 09:56 AM

在之前的文章《实用Excel技巧分享:利用 数据透视表 来汇总业绩》中,我们学习了下Excel数据透视表,了解了利用数据透视表来汇总业绩的方法。而今天我们来聊聊怎么计算时间差(年数差、月数差、周数差),希望对大家有所帮助!

实例总结Excel中AGGREGATE函数的八个用法实例总结Excel中AGGREGATE函数的八个用法May 17, 2022 am 11:37 AM

本篇文章给大家带来了关于excel的相关知识,其中主要介绍了关于AGGREGATE函数的相关内容,该函数用法与SUBTOTAL函数类似,但在功能上比SUBTOTAL函数更加强大,下面一起来看一下,希望对大家有帮助。

Word与Excel联动:表格借用Word进行分栏打印!Word与Excel联动:表格借用Word进行分栏打印!May 07, 2022 am 10:28 AM

在之前的文章《实用Word技巧分享:聊聊你没用过的“行号”功能》中,我们了解了Word中你肯定没用过的"行号”功能。今天继续实用Word技巧分享,看看Excel表格怎么借用Word进行分栏打印,快来收藏使用吧!

实用Excel技巧分享:合并单元格后实现筛选功能实用Excel技巧分享:合并单元格后实现筛选功能May 11, 2022 am 10:22 AM

在之前的文章《实用Excel技巧分享:原来“定位功能”这么有用!》中,我们了解了定位功能的妙用。而今天我们聊聊合并后的单元格如何实现筛选功能,分享一种复制粘贴和方法解决这个问题,另外还会给大家分享一种合并单元格的不错的替代方式。

实例详解利用Excel制作倒计时牌实例详解利用Excel制作倒计时牌May 16, 2022 am 11:53 AM

本篇文章给大家带来了关于excel的相关知识,其中主要介绍了关于zenmm制作倒计时牌的相关内容,使用Excel中的日期函数结合按指定时间刷新的VBA代码,即可制作出倒计时牌,下面一起来看一下,希望对大家有帮助。

Excel怎么查找总和为某个值的组合Excel怎么查找总和为某个值的组合May 18, 2022 am 11:25 AM

本篇文章给大家带来了关于excel的相关知识,其中主要介绍了关于如何使用函数寻找总和为某个值的组合的问题,下面一起来看一下,希望对大家有帮助。

图文详解Excel的折线图图文详解Excel的折线图May 07, 2022 am 11:28 AM

本篇文章给大家带来了关于excel的相关知识,其中主要介绍了关于折线图的相关问题,下面就根据一些示例来看一下怎么去应用,希望对大家有帮助。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor