str_getcsv and fgetcsv error only in CLI

Problems with the Windows version of XAMPP, questions, comments, and anything related.

str_getcsv and fgetcsv error only in CLI

Postby 76X43gKPsAha » 13. December 2016 23:43

Example function in PHP (in UTF-8)
Code: Select all
function show_csv_using_fgetcsv($csv_file)
{
   if (($handle = fopen($csv_file, "r")) !== FALSE) {
       while (($ary = fgetcsv($handle, 0, ',')) !== FALSE) {
           print_r($ary);
       }
       fclose($handle);
   }
}


Sample CSV in file (UTF-8, no BOM):
Code: Select all
1,"会","a"
2,"―","a"



instead of giving me
Code: Select all
    [0] => Array
        (
            [0] => 1
            [1] => 会
            [2] => a
        )

    [1] => Array
        (
            [0] => 2
            [1] => ―
            [2] => a
        )


it gives

Code: Select all
  [0] => Array
        (
            [0] => 1
            [1] => 会",a"
        )

    [1] => Array
        (
            [0] => 2
            [1] => ―",a"
        )


Only some characters cause the error, 会 and ― are the two of them.
It's noted only in CLI php.exe but not in browser.
Is it a known PHP 7 bug or version problem?
I did not have this back in PHP 5.2
76X43gKPsAha
 
Posts: 2
Joined: 13. December 2016 23:35
XAMPP version: 7.0.13
Operating System: Windows 10

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 40 guests