Organize the documents, and loot out a PHP implementation of CSV format file output, a little bit of streamlining to do the next share. This article mainly and everyone introduced a few lines of PHP code to achieve the CSV format file output, small series feel very good, and now share to everyone, but also for everyone to do a reference. Follow the small series together to see it, hope to help everyone.
It is suitable for the program that does not need to set the format simple to export data, many advice ... $str. = ' Pro_code '. ', '. ' Words '. ' \ n ';//First write to the table title bar foreach ($is _error as $key + = $value) {//Loop write data $str. = $value [' Pro_code ']. ",". $value [' words ']. " \ n ";} $str = Iconv (' utf-8 ', ' gb2312 ', $str);//prevent Chinese garbled $filename = "./output.csv";//file path and name Export_csv ($filename, $STR); Export//Custom output functions function Export_csv ($filename, $str) {header ("content-type:text/csv"); Header ("Content-disposition:attachment;filename=". $filename); Header (' cache-control:must-revalidate,post-check=0,pre-check=0 '); Header (' expires:0 '); Header (' Pragma:public '); echo $str;}