Bug #75244 [NEW]: fgetcsv reading failure with chinese characters
| From: | vitor dot luis98 at gmail dot com | Date: | Fri, 22 Sep 2017 07:37:29 +0000 |
| Subject: | Bug #75244 [NEW]: fgetcsv reading failure with chinese characters | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-211320@lists.php.net to get a copy of this message | ||
From: vitor dot luis98 at gmail dot com
Operating system: Windows Server 2012 - Chinese
PHP version: 7.0.23
Package: Filesystem function related
Bug Type: Bug
Bug description:fgetcsv reading failure with chinese characters
Description:
------------
When using Windows server 2012 version in Chinese language, the function
fgetcsv() does not read the line correctly and some $delimiters are lost
when splitting the line into Array.
Situation:
A CSV file with string translations, the string s are delimited by the
character ";". This is an example of the File:
id;en;cs;ja;de;ar;bg;bs;da;es;et;fr;hr;hu;is;it;ko;lt;lv;no;pl;pt;pt-br;ru;sk;sl;sr;tr;zh-cn;zh-tw
FORBIDDEN_ACCESS;Access denied;PÅÃstup
zamÃtnut;ã¢ã¯ã»ã¹ãæå¦ããã¾ãã;Zugriff
verweigert;Ø§ÙØ¯Ø®ÙÙ Ù
رÙÙØ¶;;Pristup nije odobren;Adgang
afvist;Acceso denegado;;Accès refusé;Pristup odbijen;Hozzáférés
megtagadva;;Accesso negato;ì¡ì¸ì¤ ê±°ë¶ë¨;;;;Brak dostÄpu;Acesso
negado;;РдоÑÑÑпе оÑказано;PrÃstup
zamietnutý;Dostop
zavrnjen;Pristup zabranjen;EriÅim
Engellendi;访é®è¢«æç»;åå被æçµ
Note: The empty columns are those who doesn't have a translation.
When I open this file using fopen only in read mode and use the function
fgetcsv to parse line by line, some columns are not being splitted given
to me the following output:
array(27) {
[0]=>
string(13) "Access denied"
[1]=>
string(19) "Pè¡éstup zamétnut"
[2]=>
string(36)
"éî¬åéæ±å£éå±¾å«é︺ä»é屻伍鿤¼ä»§
[3]=>
string(18) "Zugriff verweigert"
[4]=>
string(23) "ä¸è³±ä¸¿ç¦ºè³µè³± è³²ä¹è³®è³µå"
[5]=>
string(0) ""
[6]=>
string(20) "Pristup nije odobren"
[7]=>
string(13) "Adgang afvist"
[8]=>
string(15) "Acceso denegado"
[9]=>
string(0) ""
[10]=>
string(14) "Accç«s refusè
"
[11]=>
string(15) "Pristup odbijen"
[12]=>
string(24) "Hozzè°©fè
rè
s megtagadva"
[13]=>
string(0) ""
[14]=>
string(14) "Accesso negato"
[15]=>
string(20) "é§å¯é?ç¯å秬é
?"
[16]=>
string(0) ""
[17]=>
string(0) ""
[18]=>
string(13) "Brak dostèpu"
[19]=>
string(13) "Acesso negado"
[20]=>
string(0) ""
[21]=>
string(34) "è¢ åè¯è¤è¤è¤é械
è¯è¤æ³»éªè¹éªèªè¯"
[22]=>
string(20) "Préstup zamietnutåª"
[23]=>
string(15) "Dostop zavrnjen"
[24]=>
string(17) "Pristup zabranjen"
[25]=>
string(18) "Eriè§im Engellendi"
[26]=>
string(32)
"ç忣¶çî£å«ç¼?çæ¨ºå½çî£å«ç»²?"
}
But this is only happening when the script is being ran on Windows with
Chinese language, when is on English version, everything works
perfectly.
The point is, when I use the function fgets() and then explode(),
everything works fine.
Test script:
---------------
<?php
$file = fopen('dictionary.csv', 'r');
/** @var $langList array */
$langList = fgetcsv($file, 0, ";", "\n");
array_shift($langList);
while ($line = fgetcsv($file, 0, ";", "\n")) {
$id = array_shift($line);
echo "Langs = " . count($langList) . ", Line Size: ". count($line) .
"\n";
foreach ($langList as $i => $lang) {
if (isset($line[$i]) === false) {
var_dump($line);
throw new Exception(sprintf('Malformed dictionary [%s] for id [lang =
%s, index = %s].', $id, $lang, $i));
}
}
}
Expected result:
----------------
array(30) {
[0]=>
string(16) "FORBIDDEN_ACCESS"
[1]=>
string(13) "Access denied"
[2]=>
string(19) "Pè¡éstup zamétnut"
[3]=>
string(36)
"éî¬åéæ±å£éå±¾å«é︺ä»é屻伍鿤¼ä»§
[4]=>
string(18) "Zugriff verweigert"
[5]=>
string(23) "ä¸è³±ä¸¿ç¦ºè³µè³± è³²ä¹è³®è³µå"
[6]=>
string(0) ""
[7]=>
string(20) "Pristup nije odobren"
[8]=>
string(13) "Adgang afvist"
[9]=>
string(15) "Acceso denegado"
[10]=>
string(0) ""
[11]=>
string(14) "Accç«s refusè
"
[12]=>
string(15) "Pristup odbijen"
[13]=>
string(24) "Hozzè°©fè
rè
s megtagadva"
[14]=>
string(0) ""
[15]=>
string(14) "Accesso negato"
[16]=>
string(19) "é§å¯é?ç¯å秬é
?
[17]=>
string(0) ""
[18]=>
string(0) ""
[19]=>
string(0) ""
[20]=>
string(13) "Brak dostèpu"
[21]=>
string(13) "Acesso negado"
[22]=>
string(0) ""
[23]=>
string(34) "è¢ åè¯è¤è¤è¤é械
è¯è¤æ³»éªè¹éªèªè¯"
[24]=>
string(20) "Préstup zamietnutåª"
[25]=>
string(15) "Dostop zavrnjen"
[26]=>
string(17) "Pristup zabranjen"
[27]=>
string(18) "Eriè§im Engellendi"
[28]=>
string(15) "ç忣¶çî£å«ç¼?
[29]=>
string(15) "çæ¨ºå½çî£å«ç»²?
}
Actual result:
--------------
array(27) {
[0]=>
string(13) "Access denied"
[1]=>
string(19) "Pè¡éstup zamétnut"
[2]=>
string(36)
"éî¬åéæ±å£éå±¾å«é︺ä»é屻伍鿤¼ä»§
[3]=>
string(18) "Zugriff verweigert"
[4]=>
string(23) "ä¸è³±ä¸¿ç¦ºè³µè³± è³²ä¹è³®è³µå"
[5]=>
string(0) ""
[6]=>
string(20) "Pristup nije odobren"
[7]=>
string(13) "Adgang afvist"
[8]=>
string(15) "Acceso denegado"
[9]=>
string(0) ""
[10]=>
string(14) "Accç«s refusè
"
[11]=>
string(15) "Pristup odbijen"
[12]=>
string(24) "Hozzè°©fè
rè
s megtagadva"
[13]=>
string(0) ""
[14]=>
string(14) "Accesso negato"
[15]=>
string(20) "é§å¯é?ç¯å秬é
?"
[16]=>
string(0) ""
[17]=>
string(0) ""
[18]=>
string(13) "Brak dostèpu"
[19]=>
string(13) "Acesso negado"
[20]=>
string(0) ""
[21]=>
string(34) "è¢ åè¯è¤è¤è¤é械
è¯è¤æ³»éªè¹éªèªè¯"
[22]=>
string(20) "Préstup zamietnutåª"
[23]=>
string(15) "Dostop zavrnjen"
[24]=>
string(17) "Pristup zabranjen"
[25]=>
string(18) "Eriè§im Engellendi"
[26]=>
string(32)
"ç忣¶çî£å«ç¼?çæ¨ºå½çî£å«ç»²?"
}
--
Edit bug report at https://bugs.php.net/bug.php?id=75244&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75244&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75244&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75244&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75244&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75244&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75244&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75244&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75244&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75244&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75244&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75244&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75244&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75244&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75244&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75244&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75244&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75244&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75244&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75244&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75244&r=mysqlcfg