fgetcsv() ignores special characters when they are at the beginning of line!

前端 未结 4 1802
误落风尘
误落风尘 2020-12-10 14:14

I have a simple script that accepts a CSV file and reads every row into an array. I then cycle through each column of the first row (in my case it holds the questions of a s

4条回答
  •  猫巷女王i
    2020-12-10 14:49

    Are you setting your locale correctly before calling fgetcsv()?

    setlocale(LC_ALL, 'fr_FR.UTF-8');
    

    Otherwise, fgetcsv() is not multi-byte safe.

    Make sure that you set it to something that appears in your list of available locales. On linux (certainly on debian) you can see this by doing

    locale -a
    

    You should get something like...

    C
    en_US.utf8
    POSIX
    

    For UTF8 support pick an encoding with utf8 on the end. If your input is encoded with something else you'll need to use the appropriate locale - but make sure your OS supports it first.

    If you set the locale to a locale which isn't available on your system it won't help you.

提交回复
热议问题