php fgetcsv的bug

在做程序时,用户上传数据,数据中每行中有一个分隔符,然后将每行分隔成数组。在使用fgetcsv时,发现当这一行中的中文字符中含有分隔符时,它不能正常划分数组。而使用fgets每行读入之后使用explode可以正常划分数组。

字符“D^委员会办公室^翟鹏纃得滂(p1ng)腥^640^1118^n”,这是一行,这一行中使用“^”将其划分为数组。

使用fgets将这一行读取之后,使用explode划分正常,结果如下:

Array
(
    [0] => Array
        (
            [0] => D
            [1] => 委员会办公室
            [2] => 翟鹏纃得滂(p1ng)腥
            [3] => 640
            [4] => 1118
            [5] => n
        )

)

但使用fgetcsv的情况就不一样了,注意,必须是读取文件,而不是直接把字符串写在文件中

php代码:fgetcsv($handle, 1000, “^”)

结果却是这样的

Array
(
    [0] => Array
        (
            [0] => D
            [1] => 委员会办公室
            [2] => 翟鹏纃得滂(p1ng)腥^640
            [3] => 1118
            [4] => n
        )

)

看来这编码的问题,还真是比较头疼的。。。。

This entry was posted in PHP & MYSQL and tagged , , . Bookmark the permalink.

One Response to php fgetcsv的bug

  1. lafaso says:

    很喜欢贵站想与贵站做个友情链接!
    本站已做好贵站的连接,欢迎检查!
    本站名称:lafaso
    本站域名:www.wu212.cn/

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>