Example of the function implemented by php to read CSV files,
This example describes the CSV file reading function implemented by php. We will share this with you for your reference. The details are as follows:
Function read_csv ($ cvs) {$ shuang = false; $ str = file_get_contents ($ cvs); for ($ I = 0; $ I <strlen ($ str ); $ I ++) {if ($ str {$ I} = '"') {if ($ shuang) {if ($ str {$ I + 1 }== '"') {$ str {$ I} = '*'; $ str {$ I + 1} = '*';} else {$ shuang = false ;}} else {$ shuang = true ;}} if ($ str {$ I} = ',') {if ($ shuang) {} else {$ str {$ I} = '| ';}} if ($ str {$ I }== "\ n") {if ($ shuang) {$ str {$ I} = '^ ';} else {}}$ str = str_replace (array ('"', '*'), array ('', '"'), $ str ); $ a1 = explode ("\ n", $ str); $ array = array (); foreach ($ a1 as $ k = >$ value) {if ($ value) {$ value = str_replace ("^", "\ n", $ value); $ array [$ k] = explode ("|", $ value );}} return $ array ;}