csv导出姓名生僻字变问号

WBOY
Release: 2016-06-23 13:37:26
Original
2481 people have browsed it

csv导出的数据
用户姓名这一列,有几个用户的名字中带有生僻字的都变成了“?”,大部分用户的中文名字都ok,
导之前已经iconv("UTF-8","GBK",$username);但是对生僻字无效果。
生僻字如“?”,“?”,“?”,“?”


回复讨论(解决方案)

“?”,“?”,“?”,“?” 既然已收入 GBK 中,就不算生僻字了。
辞海中有十多万字,GBK 才收录了两万多点

应该是你在某处指定了字符集为 GB2312 了吧

估?是使用了其他字符集?致。

csv导出的数据
用户姓名这一列,有几个用户的名字中带有生僻字的都变成了“?”,大部分用户的中文名字都ok,
导之前已经iconv("UTF-8","GBK",$d->realname);但是对生僻字无效果。
生僻字如“?”,“?”,“?”,“?”

foreach($datas as $d)
{
$d->realname=iconv("UTF-8","GBK",$d->realname);
}
$contents = View::make('user.info_csv')->with(compact('datas'));
$response = Response::make($contents, 200);
$response->header('Content-Type', 'text/csv;charset=gb2312');
$response->header('Content-Disposition', 'attachment; filename="用户信息.csv"');
return $response;

找到问题了,mac机导出遇到生僻字就变成问号了,windows下导出正常。

不知道你的那些类是怎么写的,简单的测试一下

header("Content-type: text/csv;charset=gb2312");header("Content-Disposition: attachment; filename=用户信息.csv");echo '"?","?","?","?"';
Copy after login

并没有问题的

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
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!