Bug #72861 [Fbk->Opn]: fgetcsv get line error
| From: | cmb@php.net | Date: | Fri, 14 Sep 2018 08:35:12 +0000 |
| Subject: | Bug #72861 [Fbk->Opn]: fgetcsv get line error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-217042@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72861&edit=1
ID: 72861
Updated by: cmb@php.net
Reported by: zhouliweb at sina dot com
Summary: fgetcsv get line error
-Status: Feedback
+Status: Open
Type: Bug
Package: Filesystem function related
Operating System: Win
PHP Version: 7.0.9
-Assigned To: cmb
+Assigned To:
Block user comment: N
Private report: N
New Comment:
I *think* that fgetcsv() works as expected here, but there is some
character encoding issue. It's important to note that fgetcsv()
is locale (LC_CTYPE) aware, so the character encoding of a.csv and
LC_CTYPE have to match (or at least be compatible), *and* LC_TYPE
has to be compatible with ASCII with regard to the delimiter, the
enclosure, the escape character and the line endings (all of these
are hard coded, unless overwritten).
I guess we'd need a mb_fgetcsv() and mb_fputcsv() to solve all the
related issues.
Previous Comments:
------------------------------------------------------------------------
[2018-09-14 01:25:34] zhouliweb at sina dot com
I tried it just now(in windows with ;php7.0.9 & in centos with php7.1.12), the bug is already
exist.
orz
------------------------------------------------------------------------
[2018-09-13 16:56:06] cmb@php.net
I can't reproduce this. Is a.csv actually UTF-8 encoded? Are you
using an UTF-8 locale (LC_CTYPE)?
------------------------------------------------------------------------
[2016-08-17 03:11:30] zhouliweb at sina dot com
Description:
------------
While has japanese in the csv, fgetcsv get line error. More detail see the test script.
Test script:
---------------
$filename = "a.csv";
$file = fopen($filename, "r");
while(!feof($file) && $data = fgetcsv($file)) {
echo json_encode($data) . "\n";
}
fclose($file);
a.csv is like this:(3 lines, the first line is unix LF, others is windows CR+LF)
"a
ã¾ãããã"
b
Expected result:
----------------
["a\n\u307e\u3057\u3087\u3046\u3002"]
["b"]
Actual result:
--------------
["a\n\u307e\u3057\u3087\u3046\u3002\"\r\nb\r\n"]
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72861&edit=1