Bug #70491 [Opn->Fbk]: str_getcsv does not remove double quotes from the first row of a content
| From: | cmb@php.net | Date: | Fri, 26 Aug 2016 13:07:08 +0000 |
| Subject: | Bug #70491 [Opn->Fbk]: str_getcsv does not remove double quotes from the first row of a content | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-203574@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70491&edit=1
ID: 70491
Updated by: cmb@php.net
Reported by: msecco at gmx dot com
Summary: str_getcsv does not remove double quotes from the
first row of a content
-Status: Open
+Status: Feedback
Type: Bug
Package: Filesystem function related
Operating System: debian
PHP Version: 5.6.13
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.
A proper reproducing script starts with ,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.
Please avoid embedding huge scripts into the report.
Actually, I can't reproduce the described behavior, see
<https://3v4l.org/V8Nug>.
BTW: reading the complete CSV file, exploding at line breaks and
processing the rows with str_getcsv() will only work if there are
no line breaks embedded in a field (what is allowed in CSV files).
Previous Comments:
------------------------------------------------------------------------
[2015-09-14 13:43:14] msecco at gmx dot com
the first fields are like
"Some text" and "2222" instead of
Some text and 2222 like present in the rest of rows
thanks
------------------------------------------------------------------------
[2015-09-14 13:39:48] msecco at gmx dot com
Description:
------------
---
From manual page: http://www.php.net/function.str-getcsv
---
Hi
I'm using this function and it works well, only the first row for all its fields I need to use
str_replace(array('"', "'"), "", $line[1]) and
str_replace(array('"', "'"), "", $line[0]) to remove the
double quotes. The rest of rows are ok
if the line is this
$data .= $line[1] . ' - ' . $line[0] . "\n";
I get the double quotes
bye
Test script:
---------------
$content = file_get_contents($url);
$rows = explode("\n", $content);
foreach ($rows as $row) {
if ($row) {
$line = str_getcsv($row, "|", '"');
if ($line[1] && $line[0])
$data .= (int)str_replace(array('"', "'"), "", $line[1])
. ' - ' . str_replace(array('"', "'"), "",
$line[0]) . "\n";
}
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70491&edit=1