php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12127 Function fgetcsv() lost some letters
Submitted: 2001-07-13 01:47 UTC Modified: 2003-03-09 18:41 UTC
Votes:40
Avg. Score:3.9 ± 1.1
Reproduced:20 of 22 (90.9%)
Same Version:8 (40.0%)
Same OS:8 (40.0%)
From: bitlz at mail dot ru Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 4.3.1 OS: Windows 2000 Professional
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2001-07-13 01:47 UTC] bitlz at mail dot ru
a.csv: ( imported from microsoft excel 2000 )

???????;;;;5,58
??????? (??????????????????);;;345;9,15

a.php:

<?
$row = 1;
$fp = fopen ("a.csv","r");
while ($data = fgetcsv ($fp, 1000, ";")) {
    $num = count ($data);
    print "$num fields in line $row: <br>";
    $row++;
    for ($c=0; $c<$num; $c++) {
        print $data[$c]." ";
    }
    echo "<br>";
}
fclose ($fp);

?>

output from a.php:

5 fields in line 1: 
????? 5,58 
5 fields in line 2: 
????? (??????????????????) 345 9,15 
---------------------------------------------

some letters are lost.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-07-13 01:57 UTC] rasmus@php.net
When running your script from the command-line version of PHP I get:
5 fields in line 1: 
???????    5,58 
5 fields in line 2: 
??????? (??????????????????)   345 9,15

ie. I see no missing characters.
 [2001-07-16 01:33 UTC] bitlz at mail dot ru
may be. but when running my script from the command line php version ( on windows 2000 pro ) i get following:
---------------------------
X-Powered-By: PHP/4.0.6
Content-type: text/html

5 fields in line 1: <br>?????    5,58 <br>5 fields in line 2: <br>????? (??????????????????)   345 9,15 <br>
----------------------------
some letters are lost. :(
codepage in a.csv - cp1251.
this bug i see on different machines:
p100 ( win95 )
pIII 700 ( win2k pro )

on linux ( debian, kernel 2.4.3, php 4.0.5 ), i see next result:
----------------------
Content-type: text/html; charset=koi8-r

5 fields in line 1: <br>???????    5,58 <br>5 fields in line 2: <br>??????? (??????????????????)   345 9,15 <br>
-----------------------

on freebsd, php 4.0.4pl1 ( apache module ), and 4.0.6 ( fastcgi ) it also work properly.
 [2002-01-07 10:35 UTC] lobbin@php.net
Can you try 4.1.1?
 [2002-01-28 10:40 UTC] sander@php.net
No feedback.
 [2002-01-29 02:30 UTC] bitlz at mail dot ru
on 4.1.1 all ok.
 [2002-06-06 18:33 UTC] realktulhu at icqmail dot com
I have same bug on php 4.2.1 , WinXP
?????????;
????????;
some first letters lost.
 [2002-06-07 01:04 UTC] bitlz at mail dot ru
really, on latest version of php, bug is still alive :(
 [2002-06-07 03:24 UTC] mfischer@php.net
Is this also true for the latest development snapshot http://snaps.php.net/win32/php4-win32-latest.zip ?
 [2002-06-18 18:45 UTC] radio at degunino dot net
Yes, it's true! I'm loosing some russian-letters. I've tried to install old 4.1.1. and the bug partially has been gone, I've saw more letters but not all of them. =))) PLEASE FIX IT!

Using php latest on WinXP, IIS 5.
 [2002-07-08 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2002-07-08 08:19 UTC] tty at tty dot ru
I tried
php 4.0.5, 4.0.6, 4.1.1, 4.1.2, 4.2.0
on Win2000AS, Win2000S, WinXP
and i saw this bug =((( 
So I had to host my script on FreeBSD server. it's not good for me, because server isn't mine.

in which version of PHP this bug will be fixed?
 [2002-08-30 13:38 UTC] terrust at mail dot ru
I have the same problem (php4.2.2 + Win2000Prof).
You can use fgets() and then explode() instead of fgetcsv()till somebody fix this bug.
 [2002-12-03 03:48 UTC] pavel dot golub at farata dot kr dot ua
I have Windows 98 SE and also have such bug. But in my case there is only one missing character - russian letter "T". I use php-4.2.3
 [2003-02-28 07:13 UTC] alexws@php.net
Well, reproducing this bug on 4.3.0, 4.3.1

Code:
<?
 $fh=fopen('1.csv','rb');
 while (!feof($fh)) {
  $array[]=fgetcsv($fh,1024,';','"');
 }
 fclose($fh);
 print_r($array);
?>

CSV:
F11;KDV;?????? ????. ? ?????? ???? ????;1:53:07;598
;;Plazma - Take My Love;;
F12;Film;?????? ????. ??????? ????????;2:00:15;680
F14;????????????????;?????? ??????????? 2;2:01:53;689
F24;Bedazzled;??????????? ?????????;1:31:47;672
F27;?????????;??? ??????? ?????????;1:33:31;597

Result:
Array
(
    [0] => Array
        (
            [0] => F11
            [1] => KDV
            [2] => ?????? ????. ? ?????? ???? ????
            [3] => 1:53:07
            [4] => 598
        )

    [1] => Array
        (
            [0] => 
            [1] => 
            [2] => Plazma - Take My Love
            [3] => 
            [4] => 
        )

    [2] => Array
        (
            [0] => F12
            [1] => Film
            [2] => ?????? ????. ??????? ??????
            [3] => 2:00:15
            [4] => 680
        )

    [3] => Array
        (
            [0] => F14
            [1] => ???????????????
            [2] => ????? ??????????? 2
            [3] => 2:01:53
            [4] => 689
        )

    [4] => Array
        (
            [0] => F24
            [1] => Bedazzled
            [2] => ?????????? ?????????
            [3] => 1:31:47
            [4] => 672
        )

    [5] => Array
        (
            [0] => F27
            [1] => ????????
            [2] => ?? ??????? ?????????
            [3] => 1:33:31
            [4] => 597
        )

    [6] => 
)

Looks like it still loses foreign letters. Please REMOVE all foreign letter checks from FGETCSV. Strange behavior sometimes results in entire fields being lost.

 [2003-02-28 07:13 UTC] alexws@php.net
Well, reproducing this bug on 4.3.0, 4.3.1

Code:
<?
 $fh=fopen('1.csv','rb');
 while (!feof($fh)) {
  $array[]=fgetcsv($fh,1024,';','"');
 }
 fclose($fh);
 print_r($array);
?>

CSV:
F11;KDV;?????? ????. ? ?????? ???? ????;1:53:07;598
;;Plazma - Take My Love;;
F12;Film;?????? ????. ??????? ????????;2:00:15;680
F14;????????????????;?????? ??????????? 2;2:01:53;689
F24;Bedazzled;??????????? ?????????;1:31:47;672
F27;?????????;??? ??????? ?????????;1:33:31;597

Result:
Array
(
    [0] => Array
        (
            [0] => F11
            [1] => KDV
            [2] => ?????? ????. ? ?????? ???? ????
            [3] => 1:53:07
            [4] => 598
        )

    [1] => Array
        (
            [0] => 
            [1] => 
            [2] => Plazma - Take My Love
            [3] => 
            [4] => 
        )

    [2] => Array
        (
            [0] => F12
            [1] => Film
            [2] => ?????? ????. ??????? ??????
            [3] => 2:00:15
            [4] => 680
        )

    [3] => Array
        (
            [0] => F14
            [1] => ???????????????
            [2] => ????? ??????????? 2
            [3] => 2:01:53
            [4] => 689
        )

    [4] => Array
        (
            [0] => F24
            [1] => Bedazzled
            [2] => ?????????? ?????????
            [3] => 1:31:47
            [4] => 672
        )

    [5] => Array
        (
            [0] => F27
            [1] => ????????
            [2] => ?? ??????? ?????????
            [3] => 1:33:31
            [4] => 597
        )

    [6] => 
)

Looks like it still loses foreign letters. Please REMOVE all foreign letter checks from FGETCSV. Strange behavior sometimes results in entire fields being lost.

 [2003-02-28 07:16 UTC] moriyoshi@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

I've already committed a fix for this issue.

 [2003-02-28 07:25 UTC] moriyoshi@php.net
And actually bug #21689 is a duplicate of this report...

 [2003-03-09 18:41 UTC] sniper@php.net
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 "Open". Thank you.


 [2006-11-24 09:32 UTC] info at netangels dot ru
Guys

The problem still occurs even in PHP 5.2.0 and PHP 5.1.x as well as in 5.0.x but we've found a workaround.
If csv-file is in russian encoding (cp1251) then php-script should do:
setlocale(LC_ALL, "ru_RU");
BEFORE call fgetcsv() if current locale is not ru_RU. If locale is ru_RU already, it works well on all versions of php from 4.3.x up to the latest 5.2.0 without requiring setlocale()
 [2007-06-01 12:58 UTC] laus at tinevej dot dk
I got the same problem in php-5.2.2 with danish special letters (???) when it is saved in iso-8859-1.
But if i save the csv files as utf-8 the problem disappears.
 [2008-05-01 15:26 UTC] steve at goooooogle dot com
confirming on PHP 5.2.0-8

Csv file line:-
1,Alert Status,?tat de l'alerte

fgetcsv ignores the ?
It only happens if ? is right after the delimiter ,

Only way I got around this was to save the file as UTF8 as mention in the earlier comment. Didnt work even with setlocale(LC_ALL,'fr_FR.ISO-8859-1')
 [2008-05-11 10:21 UTC] pienkowskip at gmail dot com
it's very strange that when I run script by shell interpreter it's works properly, but when my Apache runs it there is a problem (mentioned above)
 [2008-05-11 10:37 UTC] pienkowskip at gmail dot com
I found out that locale in shell interpreter is 'pl_PL.UTF-8', but my Apache is using 'C' locale.
I added to script: setlocale(LC_ALL, 'pl_PL.UTF-8'); and I has no problems with fgetcsv().
I think it should be fixed, because csv standard doesn't mention about locales or encodings - csv is rather binary than textual.
 [2011-08-19 12:48 UTC] gtisza at gmail dot com
Duplicate of bug 45356?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 05:01:29 2024 UTC