当数据具有UTF8字符时,PHP导出CSV [英] PHP export CSV when data having UTF8 charcters

查看:70
本文介绍了当数据具有UTF8字符时,PHP导出CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MySQL中,我将数据字段类型设置为 utf8_bin ,并且我将数据存储为Unicode。文字已正确显示在网页中。

In MySQL I have set my data field type to utf8_bin and i am storing data in Unicode. Texts are being properly displayed in web pages.

我想生成将表中的数据导出到其中的excel文件。 .xls .cvs 的输出是-‘????’。

I want to generate excel file exporting data from my table to it. The output in .xls and .cvs is - '????'.

我在这里签出其他答案,它被称为使用标头:

I checkout out other answers here, its been referred to use headers:

header( content-type:application / csv; charset = UTF-8);

类似问题。但是它不起作用。使用标头后,在csv中输出为-सà¥,रà¥à¤¯à¤¾¾。

similar question. But its not working. After using header, in csv Output is - सूरà¥à¤¯à¤¾.

请帮助。谢谢。

推荐答案

此帖子解决了我的问题: https://stackoverflow.com/a/4762708/2349494

This post solved my problem: https://stackoverflow.com/a/4762708/2349494

这就是转换的内容:

print chr(255) . chr(254) . mb_convert_encoding($csv_output, 'UTF-16LE', 'UTF-8');

早些时候我得到了垃圾字符,现在可以导出正确的数据。

Earlier I was getting garbage characters now correct data is exported.

这篇关于当数据具有UTF8字符时,PHP导出CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆