|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-12-12 01:30 UTC] jani@php.net
[2009-12-12 01:31 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 18:00:01 2025 UTC |
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) "??? ?????" }