问题
When trying to import a CSV file, Arabic characters vanish when running fgetcsv
, yet when I print the output from fopen
, the Arabic characters are displayed just fine. The strange thing is that this is only happening in our production environment and not in my development environment, where fgetcsv
reads the Arabic characters just fine. Is there some server setting that's not set correctly in production?
回答1:
fgetcsv()
makes assumptions about the file's encoding based on the system locale. As the PHP manual states:
Locale setting is taken into account by this function. If
LANG
is e.g.en_US.UTF-8
, files in one-byte encoding are read wrong by this function.
You might want to compare the locale settings on your two machines and either permanently change it on one of them, or use something like setlocale(LC_ALL, 'ar_AE.utf8')
(the second argument would obviously depend on your file's encoding) before your fgetcsv()
.
来源:https://stackoverflow.com/questions/18282803/fgetcsv-not-reading-arabic-characters