php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43835 misstyped fields num in actual results
Submitted: 2008-01-14 00:17 UTC Modified: 2008-01-14 13:39 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: alexander dot varchenko at gmail dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.2.5 OS: FreeBSD,Linux,Windows
Private report: No CVE-ID: None
 [2008-01-14 00:17 UTC] alexander dot varchenko at gmail dot com
Description:
------------
Not every programs escapes enclosure characters, 
so it's should be good to check enclosures by delimiters chars
start =delimiter+enclosure
fin = enclosure+delimiter

TEST data: test.csv [TSV]
1[tab]"NOAA "Official" Emergency"[tab]01/09/2008
2[tab]"Tories "reject" green" panel's advice"[tab]01/09/2008

Reproduce code:
---------------
<?
$handle = fopen('test.csv','rb');
	$row = 1;
	while (($data = fgetcsv($handle, 1000, "\t",'"')) !== FALSE) {
    	$num = count($data);
    	echo "$num fields in line $row\n";
    	$row++;
    	for ($c=0; $c < $num; $c++) {
        	echo "[$c]:".$data[$c]."\n";
    	}
	}
	fclose($handle);
?>

Expected result:
----------------
3 fields in line 1
[0]:1
[1]:NOAA "Official" Emergency
[2]:01/09/2008
3 fields in line 2
[0]:2
[1]:Tories "reject" green" panel's advice
[2]:01/09/2008

Actual result:
--------------
4 fields in line 1
[0]:1
[1]:NOAA Official" Emergency"
[2]:01/09/2008
4 fields in line 2
[0]:2
[1]:Tories reject" green" panel's advice"
[2]:01/09/2008

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-14 00:20 UTC] alexander dot varchenko at gmail dot com
! In Actual Result -> 3 fields in line x
 [2008-01-14 13:39 UTC] iliaa@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

An invalid CSV format is not going to be supported. The enclosure 
character needs to be escaped to ensure proper data parsing.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 05:01:30 2024 UTC