To read a CSV file in this way:
All the data is taken out at once, the first line of the file is the title, the second row is to take the data, how to take?
Also read the non-English characters displayed as garbled, how to deal with it?
Reply content:
To read a CSV file in this way:
All the data is taken out at once, the first line of the file is the title, the second row is to take the data, how to take?
Also read the non-English characters displayed as garbled, how to deal with it?
1. The while before adding a row fgets ($file);
2. Your file encoding is what, the display should be what code, figure out later with iconv/mbstring transcoding a bit better.
1. At the top of the page, add: Header ("Content-type:text/html;charset=utf-8");
2.
Another way:
$str = file_get_contents ("Contacts.csv"); $arr = explode ("\ n", $str);p rint_r ($arr [1]);
$file = fopen ("Contacts.csv", "R"), Fgetcsv ($file), while (!feof ($file) && $data = Fgetcsv ($file)) { $csv _ Datas = Array (), $csv _datas[' column1 ') = Mb_convert_encoding ($data [1], ' UTF-8 ', ' Utf-8,shift_jis '); // ...}
It is worth noting that the first column to add the extra columns, the real data from the second column only to read the right, I do not know why.