|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-06-25 17:45 UTC] al at txtlocal dot com
Description: ------------ If you have csv file: name,price James,?150 fgetcsv() will remove the ?. All other chars seem to be fine. I have searched forums for an answer to this and there are a few people reporting the same - but no definitive answer. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 00:00:01 2025 UTC |
if have the same problem with php 5.2.6 the csv file looks like this: ???123???;auo123??? $handle = fopen($path."Mappe3.csv","r"); while ($data = fgetcsv ($handle, 4096, ";")) { print_r($data); } fclose ($handle); Array ( [0] => 123??? [1] => auo123??? ) with PHP 5.2.5 and 4.4.8 everything is ok ? is this a bug or a feature ?fgetcsv() seems to throw the first character away if it is invalid in the current locale, but ignores invalid characters which are not at the beginning of a cell. This code reproduces the problem in PHP 5.3.6: <?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" ?> I agree with the commenter in bug 12127 that a CSV function should not mess with encodings in the first place, just copy the content byte-by-byte.