search

Home  >  Q&A  >  body text

Regarding the fgetcsv operation problem in the tutorial

$data = [
[1,'Deng','php'],
[1,'Deng','html'],
[1,'Deng','css' ]
];
foreach ($data as $v){
fputcsv($file,$v);
}
print_r(fgetcsv($file));

微信截图_20190118213813.png微信截图_20190118213835.png

There is no problem with the code and the written csv file, but the format of the printed array is wrong.

Finally find out, Deng. Just change it to English. What's the answer? Doesn’t it support Chinese writing?


学海无涯学海无涯2180 days ago1234

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2019-01-23 20:40:23

    fgetcsv is sensitive to locale settings. For example, if LANG is set to en_US.UTF-8, single-byte encoded files will have read errors.

    setlocale(LC_ALL, 'zh_CN'); Set Simplified Chinese

    Then check the csv file encoding problem, open the csv with Notepad, the encoding setting is consistent with the server, such as utf8

    reply
    0
  • Cancelreply