I know there are a lot of similar question has already been asked in this community but unfortunately nothing gonna work for me.
I have a CSV sheet which I need to import in our system. Sheet is getting imported without any issue in linux (creating the sheet with Libre Office) even with Irish charecter.
But main problem starts in Windows and iOS environment with excel (MS-excel) where charecter encoding get changed. And few of the Irish charectors like
Ž, Ŕ and many others are getting changed to different symbols.
P.S : CSV is working fine if we are creating that through Numbers in iOS.
Below is the php method by which I'm reading the CSV sheet.
$path = CUploadedFile::getInstance($model, 'absence_data_file'); // Get the instance of selected file $target = ['First Name', 'Last Name', 'Class', 'Year', 'From']; // Valid Header public static function readCSV($path, $target) { $updated_header = array(); $data = array(); if ($path->type == 'text/csv' || $path->type == 'application/vnd.ms-excel' || $path->type == 'text/plain' || $path->type == 'text/tsv') { $fp = fopen($path->tempName, 'r'); $encoding_type = mb_detect_encoding(file_get_contents($path->tempName)); if ($fp !== FALSE) { $header = fgetcsv($fp); foreach ($header as $h) { $updated_header[] = $h; } $updated_header = array_map( 'trim', array_values($updated_header)); if (array_diff($target, $updated_header)) { $errormessage = 'Invalid header format.'; return $errormessage; } else { while ($ar = fgetcsv($fp)) { $data[] = array_combine($updated_header, $ar); } $data['file_encoding'] = $encoding_type; return $data; } } } else { $errormessage = "Invalid File type, You can import CSV files only"; return $errormessage; } } Sheet which I'm importing (Check the pic):
Printing the data (First Record)
https://stackoverflow.com/questions/66148629/irish-accent-get-changed-to-wiered-charecter-while-processing-the-csv-file-in-ph February 11, 2021 at 12:07PM

没有评论:
发表评论