I have a php script that reads a csv file (it has UTF-16LE encoding).
The problem is that at some lines the array of php reading the lines of the csv is collapsed because of some Greek characters.
A example is bellow (there are 7 elements at the array and the bellow has only 2), how can I solve this problem?
Array
(
[0] => 205198
[1] => Label 4.2 Βάση για Σ▒
)
My code is bellow
$array = file_get_contents($this->listUrl);
$array = mb_convert_encoding($array, 'UTF8', 'UTF-16LE'); // Convert the file to UTF8
$array = preg_split("/\R/", $array); // Split it by line breaks
$array = array_map(function ($v) {
return str_getcsv($v, ";");
}, $array);
Where exactly does the problem start? That is, is it getting into $array in your first statement correctly, and then going wrong subsequently? Maybe using fread() (which is described as a “binary safe file reader”) might be more successful? That would only help of course if it’s the initial read that’s causing it.
Thank you for the replay.
I set the code bellow but the problem exists , I suppose that the problem is at str_getcsv function since the code bellow does not solve the problem