>php教程 >php手册 >탭 또는 쉼표로 구분된 CSV 생성

탭 또는 쉼표로 구분된 CSV 생성

WBOY
WBOY원래의
2016-09-25 09:24:131589검색
<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으로 문의하세요.