From: gauweiler at epoq dot de
Operating system:
PHP version: 5.5.1
Package: Filesystem function related
Bug Type: Bug
Bug description:fgetcsv not working for Unicode delimiter
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"
)
--
Edit bug report at https://bugs.php.net/bug.php?id=65368&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=65368&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=65368&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=65368&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65368&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65368&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65368&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65368&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65368&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65368&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65368&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=65368&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=65368&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65368&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65368&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65368&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65368&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65368&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65368&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65368&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65368&r=mysqlcfg