从MySQL导出汉字
我在将查询结果导出到 XLS 文件时遇到中文字符问题。在我的数据库中,汉字的存储方式如下所示:
新里程集团
当我在网页上显示这些字符时,它们会借助 PHP 提供的标头函数自动转换为标准汉字。但是我们想从MySQL中用标准汉字提取XLS文件的汉字。
I have a problem with Chinese characters while exporting query results to an XLS file. In my database Chinese character are stored like as encoded format like this
新里程集团
When I show these character on a webpage they are automatically converted in standard Chinese characters with the help of a header function provided by PHP. But we want to extract Chinese characters for an XLS file from MySQL with standard Chinese character.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
mplungjan的建议是正确的,但做起来并不容易。
作为临时解决方案,您可以使用 iconv 或 mb_convert_encoding。
mplungjan's advice is correct, but it's not so easy to do.
As temporary solution, you can use iconv or mb_convert_encoding.
试试这个
mysqli_set_charset($connect,"utf8");
Try this
mysqli_set_charset($connect,"utf8");
很抱歉让它起死回生,但由于这是谷歌针对这个问题的第一个结果,我想我会在把头撞到墙上一个小时后分享我的解决方案。
如前所述,mySQL 中的数据应存储为 UTF8,列也应为 UTF8 (utf8mb4_general_ci)。
问题不在于导出本身,而在于 Excel - 当导出的文件以 UTF8 编码并且 Excel 数据以 ANSI 处理时,就会发生这种情况(如果您只是通过单击文件打开文件,则默认情况下会发生这种情况)。
您需要将文件导入 Excel,如下所示:
瞧!如果有人对此有更简单的解决方案 - 请分享。天啊都21世纪了我们还是得面对这样的垃圾
Sorry for bringing it back from the dead but since this is the first result in Google to this problem I thought I'd share my solution after banging my head against the wall for an hour.
As mentioned your data in mySQL should be stored as UTF8 and the columns should also be UTF8 (utf8mb4_general_ci).
The problem is not the export itself but the Excel - this happens when the exported file is encoded in UTF8 and Excel data is handled in ANSI (which happens by default if you just open the file by clicking on it).
You need to import the file into Excel like this:
Voila! If anyone have an easier solution for this - please share. Gosh it's the 21st century and we still have to deal with crap like this