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

生成Tab键或逗号分隔的CSV

WBOY
Libérer: 2016-09-25 09:24:13
original
1603 Les gens l'ont consulté
<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>;
Copier après la connexion

 

<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>;
Copier après la connexion

 

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Recommandations populaires
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal