php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41668 fgetcsv(): wrong parse of double quote when combined with enclosure
Submitted: 2007-06-12 10:03 UTC Modified: 2007-07-03 07:12 UTC
From: jkapicak at chip dot de Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.2.3 OS: Debian / Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jkapicak at chip dot de
New email:
PHP Version: OS:

 

 [2007-06-12 10:03 UTC] jkapicak at chip dot de
Description:
------------
If the double quote is close to enclosure, fgetcsv parses the line wrong.
This is parsed wrong: "200"|"15,4""|"aa"
When escaped, it would work: "200"|"15,4\""|"aa"

Jozef

Reproduce code:
---------------
test.csv:

"200"|"15,4""|"aa"
"200"|"15,4 "|"aa"

text.php:

<?php

$aOut = array();
$handle = fopen("test.csv", "r");
while (($data = fgetcsv($handle, 100, '|', '"')) !== FALSE) {
    print_r($data);
}
fclose($handle);

?> 

Expected result:
----------------
Array
(
    [0] => 200
    [1] => 15,4"
    [2] => aa
)
Array
(
    [0] => 200
    [1] => 15,4
    [2] => aa
)


Actual result:
--------------
Array
(
    [0] => 200
    [1] => 15,4"|aa"
)
Array
(
    [0] => 200
    [1] => 15,4
    [2] => aa
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-03 07:12 UTC] tony2001@php.net
"If a field's value contains a double quote character it is escaped by placing another double quote character next to it."
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 13:01:36 2025 UTC