ID:               50456
 Updated by:       [email protected]
 Reported By:      pahan at hubbitus dot spb dot su
-Status:           Open
+Status:           Bogus
 Bug Type:         Filesystem function related
 Operating System: Linux
 PHP Version:      5.3.1
 New Comment:

Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

See bug #45708


Previous Comments:
------------------------------------------------------------------------

[2009-12-11 22:57:44] pahan at hubbitus dot spb dot su

Description:
------------
If in unicode locale we construct CSV-file by fputcsv some values, such
as single words does not enclosed (even if enclosing character was
directly provided). Because that, in different locale file can't be
parsed properly. Be aware, I seen note in documentation, but I speak
about binary-safe parsing, do not interpret any symbols.

In followed example we get result csv-string:
Test;ÂÕáâ;"´ÒÐ áÛÞÒÐ"
Single wod is not enclosed. And I do not seen parameter to force
enclosing it. But, it can completely solve problem! So, csv-string:
"Test";"ÂÕáâ";"´ÒÐ áÛÞÒÐ"
correctly parsed in any locale (I repeat, I do not speak about further
symbol interpretation)!

So, as easy fix, which also should not produce any backward capability
problem my suggestion is add parameter to fputcsv to force enclosing
fields, even if it consist from 1 word. Or, may be even do this as
default behavior.

Reproduce code:
---------------
<?
$fp = fopen('php://temp', 'w');
fputcsv($fp, array('Test', 'ÂÕáâ', '´ÒÐ áÛÞÒÐ'), ';', '"');
rewind($fp);
echo(stream_get_contents($fp));
rewind($fp);
var_dump(fgetcsv($fp, 0, ';', '"'));
setlocale(LC_ALL, 'C');
rewind($fp);
var_dump(fgetcsv($fp, 0, ';', '"'));
?>

Expected result:
----------------
Test;ÂÕáâ;"´ÒÐ áÛÞÒÐ"
array(3) {
  [0]=>
  string(4) "Test"
  [1]=>
  string(8) "ÂÕáâ"
  [2]=>
  string(17) "´ÒÐ áÛÞÒÐ"
}
array(3) {
  [0]=>
  string(4) "Test"
  [1]=>
  string(0) "ÂÕáâ"
  [2]=>
  string(17) "´ÒÐ áÛÞÒÐ"
}


Actual result:
--------------
Test;ÂÕáâ;"´ÒÐ áÛÞÒÐ"
array(3) {
  [0]=>
  string(4) "Test"
  [1]=>
  string(8) "ÂÕáâ"
  [2]=>
  string(17) "´ÒÐ áÛÞÒÐ"
}
array(3) {
  [0]=>
  string(4) "Test"
  [1]=>
  string(0) ""
  [2]=>
  string(17) "´ÒÐ áÛÞÒÐ"
}



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=50456&edit=1

Reply via email to