The csv file generated by php cannot fully display the numbers with leading 0. when a csv file is generated by php, if the first digit of the number is 0, the first 0 is not displayed.
You can perform special processing in php so that the generated csv can display the first 0
There are two ways to achieve this:
1. enclose the number with quotation marks and add an equal sign before the quotation marks. for example, if the number is 0555, the value is = "0555"
2. add a tab to the front of the number. if the number is 0555, \ t0555 is generated.
$ Arr = array ('20160301', 111, '20160301'), array ('20160301', 2222, '20160301'); $ fp = fopen('t.csv ', 'W'); foreach ($ arr as $ row) {fputcsv ($ fp, array_map ('H', $ row);} fclose ($ fp ); function h ($ v) {if ($ v {0} = '0') & is_numeric ($ v) {$ v = '= "'. $ v. '"'; // method 1 // $ v =" \ t {$ v} "; // method 2} return $ v ;}
Reprinted from: http://www.9958.pw/post/php_cvs