我正在使用这种方法将法语转换为英语。当我从我的 html 表单中获取法语字符时,它运行良好。但我必须上传包含一些法语字符的 csv 文件。上传 csv 文件时它没有转换。
这是我上传 csv 时的代码
function UploadQuiz(){
$row =& $this->getTable('quiz');
$fileName='uploadFile';
$fileName=$_FILES['uploadFile']['tmp_name'];
$f = fopen($fileName,"r");
$success_counter=0; $failure_counter=0;
while ( ($data = fgetcsv($f, 10000, ",") ) !== FALSE ){
//perform string escapes so data is entered into database correctly
$quiz_question = $data[0];
$option_a = $data[1];
$option_b = $data[2];
$option_c = $data[3];
$option_d = $data[4];
$option_e = $data[5];
$quiz_answer = $data[6];
$quiz_explanation = $data[7];
$quiz_difficulty = $data[8];
$chapter_id = $data[9];
$chapter=$this->check_chapter_id_exist($this->_data['course_id'],$chapter_id);
if(!$chapter->chapter_id){
$failure_counter++;
continue;
}
$data['quiz_id'] = '';
$data['course_id'] = $this->_data['course_id'];
$data['quiz_question'] = $this->_convertgsm->convertgsm($quiz_question);
$data['quiz_optionA'] = $this->_convertgsm->convertgsm($option_a);
$data['quiz_optionB'] = $this->_convertgsm->convertgsm($option_b);
$data['quiz_optionC'] = $this->_convertgsm->convertgsm($option_c);
$data['quiz_optionD'] = $this->_convertgsm->convertgsm($option_d);
$data['quiz_optionE'] = $this->_convertgsm->convertgsm($option_e);
return $data;
}
这是我的php文件中的方法:
function convertgsm($data){
$normalizeChars = array(
'`'=>"'",'Ë'=>'E','Â'=>'A','À'=>'A','Í'=>'I', 'Ì'=>'I', 'Ã'=>'A', 'Î'=>'I', 'Ä'=>'A','Ç'=>'C','Ò'=>'O','Ï'=>'I','È'=>'E','Ó'=>'O','É'=>'E','Ô'=>'O','Ê'=>'E','Õ'=>'O','Ö'=>'O','ê'=>'e','Ù'=>'U','ë'=>'e','Ú'=>'U','ë'=>'e','Ú'=>'U','î'=>'i','Û'=>'U','Û'=>'U','Ü'=>'U','ô'=>'o','Ý'=>'Y','õ'=>'o','â'=>'a','û'=>'u','ã'=>'a','ÿ'=>'y','ç'=>'c','ï'=>'i'
);
$result_data = strtr($data, $normalizeChars);
return $result_data;
}
你能帮我在上传 csv 文件时将法语转换为英语吗?