This article describes how to write data from php to CSV files. it involves the skills of php to operate csv files and is of great practical value, for more information about how to write php Data to a CSV file, see the following example. Share it with you for your reference. The specific implementation method is as follows:
<? Php $ row = 0; ini_set ('max _ execution_time ', 300); $ cate; $ item; $ value; $ us; $ fp = fopen ("torah1.csv ", "w"); if ($ handle = fopen ("t.csv", "r "))! = FALSE) {while ($ data = fgetcsv ($ handle, 1000 ,","))! = FALSE) {$ num = count ($ data); $ row ++; for ($ c = 0; $ c <$ num; $ c ++) {if ($ c = 0) {$ us = $ data [$ c];} if ($ c = 1) {$ item = explode ("", $ data [$ c]); echo""; Print_r ($ item);} elseif ($ c = 2) {$ value = $ data [$ c];} elseif ($ c = 3) {$ cate1 = $ data [$ c];} else {}}// end of for loop if ($ row> 1838) {exit;} fputcsv ($ fp, array ($ us, $ item [0], $ item [1], $ item [2], $ item [3]);} // End of While} // End of IF fclose ($ handle); fclose ($ fp);?>
I hope this article will help you with php programming.