This (http://www.linuxidc.com/Linux/2011-08/40394p2.htm) describes the use of the fgets method to replace fgetcsv to read the csv file, and later found that if not directly replaced by the processing, there is still a problem: really make me depressed for a long time ah. First, fgetcsv correctly processes the content in a row during processing. Even if the row contains line breaks and line breaks, it can be processed and parsed correctly. However, if you use fgets, you need to do this by yourself.
This (http://www.linuxidc.com/Linux/2011-08/40394p2.htm) describes the use of the fgets method to replace fgetcsv to read the csv file, and later found that if not directly replaced by the processing, there is still a problem: really make me depressed for a long time ah.
First, fgetcsv correctly processes the content in a row during processing. Even if the row contains line breaks and line breaks, it can be processed and parsed correctly. If you use fgets, you need to do this by yourself. Of course, a method to rewrite fgetcsv is also provided on the Internet. Of course, you need to consider the efficiency of using regular expressions.
However, fgetcsv has a problem. As mentioned in the previous article, the region settings, of course, setlocale (LC_ALL, 'zh _ cn'). It turns out that it can be solved, however, this is a test in WIN. The tragedy occurred when I moved to Ubuntu for testing.
Although my ubuntu system uses the Chinese language, the local code is zh_CN.UTF8, and there is no zh_CN.GBK. Therefore, the Chinese text cannot be parsed.
Of course, the shoulders of the predecessors are always great. With the help of the Internet, everything can be solved.
First, I updated the Language Pack, system-> Management-> language support. When I started it for the first time, I was prompted that I didn't install it completely and needed to upgrade it. So I upgraded it, but when I checked locale-a in the command line, there was still no zh_CN:
Www.linuxidc.com @ ubuntu:/usr/www/GBKHost/test $ locale-
C
POSIX
Zh_CN.utf8
Zh_HK.utf8
Zh_SG.utf8
Zh_TW.utf8
So I did this:
1. Modify the local file and add zh_CN support:
Sudo vi/var/lib/locales/supported. d/local
Insert a row of zh_CN in front of the first row. In this case, I also inserted the row zh_CN.GBK GBK.
Save.
2. Set the support package
Sudo locale-gen zh_CN
Sudo locale-gen zh_CN.GBK
3. Run locale-a again.
Www.linuxidc.com @ ubuntu:/usr/www/GBKHost/test $ locale-
C
POSIX
Zh_CN
Zh_CN.gb2312
Zh_CN.gbk
Zh_CN.utf8
Zh_HK.utf8
Zh_SG.utf8
Zh_TW.utf8
Finally.
Run the csv import page again (including setlocale (LC_CTYPE, 'zh _ cn!