Bug #75244 [Fbk->NoF]: fgetcsv reading failure with chinese characters
| From: | php-bugs at lists dot php dot net | Date: | Sun, 05 Nov 2017 04:22:55 +0000 |
| Subject: | Bug #75244 [Fbk->NoF]: fgetcsv reading failure with chinese characters | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-212462@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75244&edit=1
ID: 75244
Updated by: php-bugs@lists.php.net
Reported by: vitor dot luis98 at gmail dot com
Summary: fgetcsv reading failure with chinese characters
-Status: Feedback
+Status: No Feedback
Type: Bug
Package: Filesystem function related
Operating System: Windows Server 2012 - Chinese
PHP Version: 7.0.23
Private report: N
New Comment:
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
Previous Comments:
------------------------------------------------------------------------
[2017-09-25 14:14:42] jhdxr@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php
If you can provide more information, feel free to add it
to this bug and change the status back to "Open".
Thank you for your interest in PHP.
What's your locale setting? And what's the encoding of the csv file?
------------------------------------------------------------------------
[2017-09-22 07:37:20] vitor dot luis98 at gmail dot com
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 this bug report at https://bugs.php.net/bug.php?id=75244&edit=1