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

生成Tab键或逗号分隔的CSV

WBOY
WBOYasal
2016-09-25 09:24:131591semak imbas
<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>;

 

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn