Home > Backend Development > PHP Tutorial > php generate tab or comma separated CSV

php generate tab or comma separated CSV

高洛峰
Release: 2023-03-03 20:36:01
Original
1369 people have browsed it

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;
Copy after login
<?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;
Copy after login

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!


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template