Codeigniter's csv_from_result() not working with UTF-8 characters? Codeigniter's csv_from_result() not working with UTF-8 characters? codeigniter codeigniter

Codeigniter's csv_from_result() not working with UTF-8 characters?


csv_from_result from ci generates utf-8 without BOM, and you can find the difference here so all you need to do now is to convert "utf-8 without BOM" to "utf-8", and you can do it with the following code.

$this->load->dbutil();$delimiter = ",";$newline = "\r\n";$report_result =  $this->data_model->get_data_result();$CSV_data      = $this->dbutil->csv_from_result($report_result, $delimiter, $newline);$CSV_data = chr(239) . chr(187) . chr(191) .$CSV_data;$data['csv'] = $CSV_data;


Try this:

$this->load->dbutil();$query = $this->db->query($sql);$delimiter = ",";$newline = "\r\n";header ("Content-disposition: attachment; filename=csvoutput_" . time() . ".csv") ;echo mb_convert_encoding($this->dbutil->csv_from_result($query, $delimiter, $newline), "ISO-8859-1", "UTF-8");