I have this code in a UTF-8 encoded file:
<?php setlocale(LC_ALL, 'cs_CZ.utf8'); //Can be commented out without effect. $input = "Štěpán,Šafránek"; $result = str_getcsv($input); echo $result[0]; //output = "těpán"; echo $result[1]; //output = "afránek"; ?>
Notice the trimmed lines that cause echoes.
It also works:
<?php setlocale(LC_ALL, 'cs_CZ.utf8'); //Can be commented out without effect. $input = "aaaŠtěpán,aaaŠafránek"; $result = str_getcsv($input); echo $result[0]; //output = "aaaŠtěpán"; echo $result[1]; //output = "aaaŠafránek"; ?>
Since the input line is part of the script, there should be no encoding problems, right? The language is installed correctly, right?
So what's wrong? My solution is that str_getcsv () is just broken. Any alternative way to parse CSV?
Interestingly, on Windows, this works great, but on Linux, I see this behavior.
A related question, but the resolutions mentioned there did not help: PHP str_getcsv removes umlauts
php csv diacritics
Josef Sábl
source share