Problem with £ sign writing to MySQL (solved) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Problem with £ sign writing to MySQL (solved) (/showthread.php?tid=64167) |
Problem with £ sign writing to MySQL (solved) - JohnInMaldon - 01-22-2016 I'm executing a script which reads a text file with fgetcsv and uses query builder insert to write records. All goes well, except that any string which has a £ symbol is truncated at that position. The strings are are going into varchar, and phpMyAdmin lets me edit those characters in manually. The varchar columns are specified to be utf8_general_ci. Am I doing something wrong? Any assistance will be gratefully received! The controller does : if (($handle = fopen($f, "r")) !== FALSE) { while(($data = fgetcsv($handle,1000,"\t")) !== FALSE) { //file_put_contents('debug.txt',$data[2]."\r\n",FILE_APPEND); $this->maint_model->rec_entries($data,$id); } fclose($handle); } ...and the put_file_contents verifies the data was read OK. 'rec_entries' looks like this: public function rec_entries($data,$id) { $data = array( 'ind_id' => $id, 'name' => $data[0], 'subject' => $data[1], 'event' => $data[2], 'column' => $data[5], 'doi' => $data[4], 'page' => $data[3] ); $this->db->insert('entries', $data); // Make an entries table entry return; } RE: Problem with £ sign writing to MySQL - JohnInMaldon - 01-27-2016 Is there a better forum to post this sort of question? RE: Problem with £ sign writing to MySQL (solved) - JohnInMaldon - 01-31-2016 I have found that I needed to explicitly convert the incoming data to the form I required. Obvious really, but I hadn't seen it done before! So I have done things like: $data = iconv("ISO-8859-1","UTF-8//IGNORE",$data); and all is well. Cheers! |