How does PHP export a CSV file with a leading 0? Here is a small series to bring you a PHP export CSV file, you can export the leading 0 instance code. Small series feel very good, now share to everyone, also for everyone to make a reference. We hope to help you.
Example one: can export leading 0
Export CSV format file $data data $title _arr title $file _name filename function exportcsv ($data, $title _arr, $file _name= ") {Ini_set (" Max_ Execution_time "," 3600 "); $csv _data = "; /** Title */$nums = count ($title _arr); for ($i = 0; $i < $nums-1; + + $i) {$csv _data. = ' ". $title _arr[$i]. '",'; } if ($nums > 0) {$csv _data. = ' ". $title _arr[$nums-1]. "\" \ r \ n "; } foreach ($data as $k + $row) {foreach ($row as $key + = $r) {$row [$key] = Str_replace ("\" "," \ "\" ", $r); $csv _data. = "\" \ T ". $row [$key]. '",'; } $csv _data. = ' "'. $row [$nums-1]. "\" \ r \ n "; Unset ($data [$k]); } $csv _data = mb_convert_encoding ($csv _data, "cp936", "UTF-8"); $file _name = Empty ($file _name)? Date (' Y-m-d-h-i-s ', Time ()): $file _name; if (Strpos ($_server[' http_user_agent '), "MSIE")) {//resolve bug $file _name = UrlEncode ($file _name) for IE output Chinese name garbled $file _name = str_replace (' + ', '%20 ', $file _name); } $file _name = $file _name. '. csv '; Header (' content-type:application/download ');Header ("content-type:text/csv;"); Header ("Content-disposition:attachment;filename=". $file _name); Header (' cache-control:must-revalidate,post-check=0,pre-check=0 '); Header (' expires:0 '); Header (' Pragma:public '); echo $csv _data; Exit ();}
Note: You cannot export hyperlinks directly!
Related recommendations:
PHP CSV Operation class Code
PHP csv to Array (CSV-to-array) method and code
PHP CSV Import Database