From:             
Operating system: Linux
PHP version:      Irrelevant
Package:          Filesystem function related
Bug Type:         Bug
Bug description:fgetcsv() handles invalid characters inconsistently

Description:
------------
fgetcsv() throws away the first character of a field if it is invalid in
the current locale, but ignores invalid characters which are not at the
beginning of a field. The inconsistent behavior makes it hard to locate the
source of the bug; it should either throw all invalid characters away, or
none of them (IMO the second is much better).


(This is a duplicate of bug 45356, but that one has been closed as "no
feedback", and apparently mere mortals are not allowed to reopen it, even
if they do provide the feedback...)

Test script:
---------------
<?php

setlocale(LC_ALL,'C');
$utfchar = chr(0xC3).chr(0x89); // U+009C in UTF-8

$csv = $utfchar."x".$utfchar."x\n";

file_put_contents('test.csv', $csv);
$file = fopen('test.csv', 'r');
$data = fgetcsv($file);

for ($i = 0; $i < strlen($data[0]); $i++) {
    echo dechex(ord($data[0][$i])).' ';
}
echo "\n";
unlink('test.csv');

// expected: c3 89 78 c3 89 78 - "ÉxÉx"
// actual: 78 c3 89 78 - "xÉx"

?>


-- 
Edit bug report at https://bugs.php.net/bug.php?id=55507&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=55507&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=55507&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=55507&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=55507&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=55507&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=55507&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=55507&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=55507&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=55507&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=55507&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=55507&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=55507&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=55507&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=55507&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=55507&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=55507&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=55507&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=55507&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=55507&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=55507&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=55507&r=mysqlcfg

Reply via email to