php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65368 fgetcsv not working for Unicode delimiter
Submitted: 2013-07-31 15:01 UTC Modified: 2013-08-02 01:03 UTC
From: gauweiler at epoq dot de Assigned:
Status: Duplicate Package: Filesystem function related
PHP Version: 5.5.1 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gauweiler at epoq dot de
New email:
PHP Version: OS:

 

 [2013-07-31 15:01 UTC] gauweiler at epoq dot de
Description:
------------
fgetcsv does not work if you have a unicode delimiter like § (paragraph).
setlocale() doesn't help.


Test script:
---------------
error_reporting(E_ALL);
                              
$enclosure='"';
$escape='"';

$delimiter=",";
$fh = tmpfile();
fwrite($fh,utf8_encode('"first"'.$delimiter.'"second"'.$delimiter.'"third"'."\n"));
fwrite($fh,utf8_encode('"one"'.$delimiter.'"two""two"'.$delimiter.'"three"'."\n"));
fseek($fh,0);
while (($data = fgetcsv($fh, 0, $delimiter,$enclosure,$escape)) !== FALSE) {
  print_r($data);
}
fclose($fh);

$delimiter=chr(167); // §
$fh = tmpfile();
fwrite($fh,utf8_encode('"first"'.$delimiter.'"second"'.$delimiter.'"third"'."\n"));
fwrite($fh,utf8_encode('"one"'.$delimiter.'"two""two"'.$delimiter.'"three"'."\n"));
$delimiter=utf8_encode($delimiter);
fseek($fh,0);
while (($data = fgetcsv($fh, 0, $delimiter,$enclosure,$escape)) !== FALSE) {
  print_r($data);
}

fclose($fh);


Expected result:
----------------
The line is splitted by unicode delimiter also. No warnings appear.
Array
(
    [0] => first
    [1] => second
    [2] => third
)
Array
(
    [0] => one
    [1] => two"two
    [2] => three
)
Array
(
    [0] => first
    [1] => second
    [2] => third
)
Array
(
    [0] => one
    [1] => two"two
    [2] => three
)


Actual result:
--------------
Warnings appear: "Notice: fgetcsv(): delimiter must be a single character in..."
The line is splitted using , but not using §:

Array
(
    [0] => first
    [1] => second
    [2] => third
)
Array
(
    [0] => one
    [1] => two"two
    [2] => three
)
Array
(
    [0] => first§"second"§"third"
)
Array
(
    [0] => one§"two""two"§"three"
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-02 01:03 UTC] yohgaki@php.net
-Status: Open +Status: Duplicate
 [2013-08-02 01:03 UTC] yohgaki@php.net
Basically the same issue as #55507
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC