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

生成Tab键或逗号分隔的CSV

WBOY
WBOY原创
2016-09-25 09:24:131594浏览
<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>;

 

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn