#44979 [Opn->Bgs]: Strange behavior of fgetcsv

From: Date: Tue, 13 May 2008 13:02:06 +0000
Subject: #44979 [Opn->Bgs]: Strange behavior of fgetcsv
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-124945@lists.php.net to get a copy of this message
 ID:               44979
 Updated by:       felipe@php.net
 Reported By:      great_boba at yahoo dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Filesystem function related
 Operating System: Suse
 PHP Version:      5.2.6
 New Comment:

This is expected. The "" is an escaped enclosure.

Using:
"A","B","C"
"A","B ""","C """

Array
(
    [0] => A
    [1] => B "
    [2] => C "
)

Use a proper format file.


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

[2008-05-13 10:32:21] great_boba at yahoo dot com

Description:
------------
I try to write some application which parse csv-dump. 
Below I write little example to show strange things.

Reproduce code:
---------------
1.csv
"A","B","C"
"A","B "","C """
1.php
<?php

$fp=fopen('1.csv',r');
while($data=fgetcsv($fp,4096,','))
   print_r($data);

fclose($fp);

?>

Expected result:
----------------
Array
{
  [0]=>A
  [1]=>B
  [2]=>C
}
Array
{
  [0]=>A
  [1]=>B "
  [2]=>C ""
}

Actual result:
--------------
Array
{
  [0]=>A
  [1]=>B
  [2]=>C
}
Array
{
  [0]=>A
  [1]=>B ",C """
}


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


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



Thread (3 messages)

« previous php.bugs (#124945) next »