Open CSV file with PHP
- //Set UTF-8 encoding
- setlocale(LC_ALL, 'en_US.UTF-8');
- //csv path
- $csv_file = "csv/excel.csv";
- //Open in read-only mode File
- $handle = fopen($csv_file, "r");
- //Define the result array
- $listarr = array();
- //Open a row in csv and split it into an array with ","
- while($data = fgetcsv($handle, 1000, ",")){
- $num = count($data);
- for($i=0; $i<$num; $i++){
- $data[$i] = mb_convert_encoding ($data[$i],"UTF-8","UTF-8");
- }
- $listarr[] = $data;
- }
-
- return $listarr;
Copy code
|