|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-08-02 01:03 UTC] yohgaki@php.net
-Status: Open
+Status: Duplicate
[2013-08-02 01:03 UTC] yohgaki@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 03:00:01 2025 UTC |
Description: ------------ fgetcsv does not work if you have a unicode delimiter like § (paragraph). setlocale() doesn't help. Test script: --------------- error_reporting(E_ALL); $enclosure='"'; $escape='"'; $delimiter=","; $fh = tmpfile(); fwrite($fh,utf8_encode('"first"'.$delimiter.'"second"'.$delimiter.'"third"'."\n")); fwrite($fh,utf8_encode('"one"'.$delimiter.'"two""two"'.$delimiter.'"three"'."\n")); fseek($fh,0); while (($data = fgetcsv($fh, 0, $delimiter,$enclosure,$escape)) !== FALSE) { print_r($data); } fclose($fh); $delimiter=chr(167); // § $fh = tmpfile(); fwrite($fh,utf8_encode('"first"'.$delimiter.'"second"'.$delimiter.'"third"'."\n")); fwrite($fh,utf8_encode('"one"'.$delimiter.'"two""two"'.$delimiter.'"three"'."\n")); $delimiter=utf8_encode($delimiter); fseek($fh,0); while (($data = fgetcsv($fh, 0, $delimiter,$enclosure,$escape)) !== FALSE) { print_r($data); } fclose($fh); Expected result: ---------------- The line is splitted by unicode delimiter also. No warnings appear. Array ( [0] => first [1] => second [2] => third ) Array ( [0] => one [1] => two"two [2] => three ) Array ( [0] => first [1] => second [2] => third ) Array ( [0] => one [1] => two"two [2] => three ) Actual result: -------------- Warnings appear: "Notice: fgetcsv(): delimiter must be a single character in..." The line is splitted using , but not using §: Array ( [0] => first [1] => second [2] => third ) Array ( [0] => one [1] => two"two [2] => three ) Array ( [0] => first§"second"§"third" ) Array ( [0] => one§"two""two"§"three" )