php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30335 fgetcsv + foreign characters
Submitted: 2004-10-06 10:29 UTC Modified: 2004-10-16 01:00 UTC
Votes:8
Avg. Score:4.6 ± 0.7
Reproduced:8 of 8 (100.0%)
Same Version:1 (12.5%)
Same OS:5 (62.5%)
From: gruszczol1 at poczta dot onet dot pl Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 5.0.2 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: gruszczol1 at poczta dot onet dot pl
New email:
PHP Version: OS:

 

 [2004-10-06 10:29 UTC] gruszczol1 at poczta dot onet dot pl
Description:
------------
fgetcsv() doesn't read foreign chracters which are on the beginning of the field.
Similar bug in http://bugs.php.net/bug.php?id=10896 but it has status closed.

Reproduce code:
---------------
File contains:
?abc|?abc|?abc?

Example code:
$aqq=fgetcsv($fp, 4000, "|");
echo $aqq[0].$aqq[1].$aqq[2];


Expected result:
----------------
Expected result:
?abc?abc?abc?

Actual result:
--------------
Actual result:
abcabcabc?

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-06 10:32 UTC] derick@php.net
This example is useles, as we don't know which encoding you are using.
Please put this script in a zip file and provide the link to it in this bugreport.

 [2004-10-06 11:40 UTC] gruszczol1 at poczta dot onet dot pl
It was tested with iso-8859-2 and windows-1250 text file.
http://republika.pl/gruszczol1/fgetcsv_bug_example.tgz
 [2004-10-07 01:38 UTC] iliaa@php.net
Specific to 5.X
 [2004-10-07 17:15 UTC] moriyoshi@php.net
Try setting LC_CTYPE (or LANG) environment variable to 
"pl_PL.ISO-8859-2".
 [2004-10-16 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, 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".
 [2005-11-11 13:49 UTC] mdv at inyourpocket dot com
it looks that fgetcsv depends on locales

<?php
$argv[1] = './x.txt';

if (!($fd = fopen($argv[1], 'r')))
        die('Can\'t open file');

while (!feof($fd))
        echo fgets($fd, 4096);

fclose($fd);

if (!($fd = fopen($argv[1], 'r')))
        die('Can\'t open file');

while (($l = fgetcsv($fd, 4096, "\t")))
        print_r($l);

fclose($fd);
?>

x.txt get here http://lampa.naut.cz/x.txt (text contains text windows-1250 encoding "aa?\t?vvv" \t is TAB)

result when locale POSIX:
aa?    ?vvv
Array
(
    [0] => aa?
    [1] => vvv
)

result when locale cs_CZ:
aa?    ?vvv
Array
(
    [0] => aa?
    [1] => ?vvv
)
 [2005-11-11 13:53 UTC] mdv at inyourpocket dot com
i tested in on php 5.0.5
 [2008-03-31 09:49 UTC] hkroger at gmail dot com
I can confirm that this still occurs on PHP 5.1.6 on Linux with windows-1250 text files. Please open it again.
 [2009-01-08 12:31 UTC] sandyhbdev at gmail dot com
Thanks moriyoshi,
we can do it by changing LC_CTYPE vriable.
we can read unknown char. from csv if it's begining of value,too

Thank you very much
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC