首页 > php教程 > php手册 > 生成Tab键或逗号分隔的CSV

生成Tab键或逗号分隔的CSV

WBOY
发布: 2016-09-25 09:24:13
原创
1583 人浏览过
<span style="color: #008080;">1</span> <span style="color: #000000;">php
</span><span style="color: #008080;">2</span> <span style="color: #008080;">header</span>("Content-type:text/csv;charset=utf-8"<span style="color: #000000;">);
</span><span style="color: #008080;">3</span> <span style="color: #008080;">header</span>("Content-Disposition:attachment;filename=aa.csv"<span style="color: #000000;">);
</span><span style="color: #008080;">4</span> <span style="color: #008080;">header</span>('Cache-Control:must-revalidate,post-check=0,pre-check=0'<span style="color: #000000;">);
</span><span style="color: #008080;">5</span> <span style="color: #008080;">header</span>('Expires:0'<span style="color: #000000;">);
</span><span style="color: #008080;">6</span> <span style="color: #008080;">header</span>('Pragma:public'<span style="color: #000000;">);
</span><span style="color: #008080;">7</span> <span style="color: #800080;">$data</span> = "\xEF\xBB\xBFaaaaa\tbbbbb\tccccc\n11111\t222222\t33333"<span style="color: #000000;">; // \xEF\xBB\xBF是bom头
</span><span style="color: #008080;">8</span> <span style="color: #800080;">$data</span> = <span style="color: #008080;">iconv</span>('utf-8', 'ucs-2', <span style="color: #800080;">$data</span><span style="color: #000000;">);
</span><span style="color: #008080;">9</span> <span style="color: #0000ff;">echo</span> <span style="color: #800080;">$data</span>;
登录后复制

 

<span style="color: #008080;">1</span> <span style="color: #000000;">php
</span><span style="color: #008080;">2</span> <span style="color: #008080;">header</span>("Content-type:text/csv;charset=utf-8"<span style="color: #000000;">);
</span><span style="color: #008080;">3</span> <span style="color: #008080;">header</span>("Content-Disposition:attachment;filename=aa.csv"<span style="color: #000000;">);
</span><span style="color: #008080;">4</span> <span style="color: #008080;">header</span>('Cache-Control:must-revalidate,post-check=0,pre-check=0'<span style="color: #000000;">);
</span><span style="color: #008080;">5</span> <span style="color: #008080;">header</span>('Expires:0'<span style="color: #000000;">);
</span><span style="color: #008080;">6</span> <span style="color: #008080;">header</span>('Pragma:public'<span style="color: #000000;">);
</span><span style="color: #008080;">7</span> <span style="color: #800080;">$data</span> = "aaaaa,bbbbb,ccccc\n11111,222222,33333"<span style="color: #000000;">;
</span><span style="color: #008080;">8</span> <span style="color: #800080;">$data</span> = <span style="color: #008080;">iconv</span>('utf-8', 'gbk', <span style="color: #800080;">$data</span><span style="color: #000000;">);
</span><span style="color: #008080;">9</span> <span style="color: #0000ff;">echo</span> <span style="color: #800080;">$data</span>;
登录后复制

 

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板