php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70491 str_getcsv does not remove double quotes from the first row of a content
Submitted: 2015-09-14 13:39 UTC Modified: 2016-09-04 04:22 UTC
Votes:2
Avg. Score:4.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: msecco at gmx dot com Assigned: cmb (profile)
Status: No Feedback Package: Filesystem function related
PHP Version: 5.6.13 OS: debian
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: msecco at gmx dot com
New email:
PHP Version: OS:

 

 [2015-09-14 13:39 UTC] 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";
				}
			}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-14 13:43 UTC] 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
 [2016-08-26 13:07 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2016-08-26 13:07 UTC] cmb@php.net
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).
 [2016-09-04 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 04 19:01:32 2024 UTC