How to export CSV table file with PHP

WBOY
Release: 2016-07-25 08:55:04
Original
955 people have browsed it
  1. $ret = '';
  2. $arrs = array(array(1,'test1'),
  3. array(2,'test2'),
  4. array(3,'test3') ,
  5. array(4,'test4'),
  6. array(5,'test5'),
  7. array(6,'test6'),
  8. array(7,'test7')
  9. );
  10. foreach($arrs as $ k=>$arr){
  11. $ret .= $arr[0].",".$arr[1]." n";
  12. }
  13. //$ret = @mb_convert_encoding ($ret, 'GBK' ,'UTF-8');
  14. header("Content-Disposition: attachment; filename=xxxx.csv");
  15. header("Content-Type:APPLICATION/OCTET-STREAM");
  16. echo $ret;
Copy the code

Note: The above code for exporting csv files using PHP still uses the PHP header function. I hope you can learn from it.



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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!