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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri May 10 11:01:32 2024 UTC