Home > Article > Backend Development > php generate tab or comma separated CSV
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('Cache-Control:must-revalidate,post-check=0,pre-check=0'); header('Expires:0'); header('Pragma:public'); $data = "\xEF\xBB\xBFaaaaa\tbbbbb\tccccc\n11111\t222222\t33333"; // \xEF\xBB\xBF是bom头 $data = iconv('utf-8', 'ucs-2', $data); echo $data;
<?php header("Content-type:text/csv;charset=utf-8"); header("Content-Disposition:attachment;filename=aa.csv"); header('Cache-Control:must-revalidate,post-check=0,pre-check=0'); header('Expires:0'); header('Pragma:public'); $data = "aaaaa,bbbbb,ccccc\n11111,222222,33333"; $data = iconv('utf-8', 'gbk', $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!