我正在使用此方法將法語轉換爲英語。當我從我的html表單中獲得法語字符時,它的效果很好。但我必須上傳包含法文字符的csv文件。它在上傳csv文件時沒有轉換。在php中上傳爲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文件轉換成英文?
「,而上傳「意味着您希望在傳輸過程中對其進行讀取和替換? – 2012-04-14 08:00:40
我只是解析從我的csv文件上傳的數據。然後作爲參數傳遞給該函數。 – ram 2012-04-14 08:14:59
你可以添加你使用的代碼來上傳你的CSV ....我想我可以幫助 – Baba 2012-04-14 08:51:03