str_getcsv is broken, clips diacritics?

喜夏-厌秋 提交于 2019-12-12 10:04:36

问题


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

来源:https://stackoverflow.com/questions/16653369/str-getcsv-is-broken-clips-diacritics

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!