From: alec dot cormack at cloud-corporate dot com
Operating system: LINUX
PHP version: 5.3.18
Package: Filesystem function related
Bug Type: Bug
Bug description:fgetcsv not working for Unicode files with BOM prefix
Description:
------------
In php 5.3.x when using fgetcsv to read a unicode file including a UTF-8
Byte
Order Mark (BOM) prefix 0xEF,0xBB,0xBF the first row of the file is not
read
correctly. If the BOM is removed fgetcsv reads the file correctly.
I have tried this with and without setlocale and the result is always
wrong. I
have run the same program on PHP 5.2.4 and it works.
Test File is the simplest possible csv with the BOM prefix "a" followed by
a
newline contains (7 characters in total)
0xEF,0xBB,0xBF,0x22,0x61,0x22,0x0A
When processed by fgetcsv the doublequotes should get removed and the value
a
should be in the array returned.
Test script:
---------------
<?php
echo mb_detect_encoding(file_get_contents($argv[1]))."\n";
setlocale(LC_CTYPE, 'en_GB.utf8');
$handle = fopen($argv[1], "r");
$data = fgetcsv($handle, 1000, ",");
print_r($data);
?>
Expected result:
----------------
UTF-8
Array
(
[0] => a
)
Actual result:
--------------
UTF-8
Array
(
[0] => "a"
)
--
Edit bug report at https://bugs.php.net/bug.php?id=63433&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=63433&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=63433&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=63433&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=63433&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=63433&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=63433&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=63433&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=63433&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=63433&r=support
Expected behavior: https://bugs.php.net/fix.php?id=63433&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=63433&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=63433&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=63433&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63433&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=63433&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=63433&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=63433&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=63433&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=63433&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=63433&r=mysqlcfg