fgetcsv() not reading Arabic characters

五迷三道 提交于 2020-02-05 02:38:12

问题


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

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