Home  >  Article  >  Backend Development  >  php generate tab or comma separated CSV

php generate tab or comma separated CSV

高洛峰
高洛峰Original
2016-12-21 16:05:031297browse

php The code to generate tab or comma separated CSV is as follows:

<?php
header("Content-type:text/csv;charset=utf-8");
header("Content-Disposition:attachment;filename=aa.csv");
header(&#39;Cache-Control:must-revalidate,post-check=0,pre-check=0&#39;);
header(&#39;Expires:0&#39;);
header(&#39;Pragma:public&#39;);
$data = "\xEF\xBB\xBFaaaaa\tbbbbb\tccccc\n11111\t222222\t33333"; // \xEF\xBB\xBF是bom头
$data = iconv(&#39;utf-8&#39;, &#39;ucs-2&#39;, $data);
echo $data;
<?php
header("Content-type:text/csv;charset=utf-8");
header("Content-Disposition:attachment;filename=aa.csv");
header(&#39;Cache-Control:must-revalidate,post-check=0,pre-check=0&#39;);
header(&#39;Expires:0&#39;);
header(&#39;Pragma:public&#39;);
$data = "aaaaa,bbbbb,ccccc\n11111,222222,33333";
$data = iconv(&#39;utf-8&#39;, &#39;gbk&#39;, $data);
echo $data;

The above is the php generated by the editor to generate tab or comma separated CSV. I hope it will be helpful to everyone. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank you all for your support of the PHP Chinese website!

For more articles related to PHP generating tab- or comma-delimited CSV, please pay attention to the PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn