I have a code like this in a file that is UTF-8 encoded:
<?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 clipped strings those echoes produce.
Also this 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";
?>
As the input string is part of script there should be no problem with encoding, right? Locale is set correctly, right?
So what is wrong? My resolution is that str_getcsv() is just plain broken. Any alternative way to parse CSV?
It is interesting that on Windows it works fine but on Linux I see this behavior.
Related question here, but resolutions mentioned there did not help: PHP str_getcsv removes umlauts