php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69800 fgetcsv ignores empty trailing field with tab delimiter
Submitted: 2015-06-11 14:09 UTC Modified: 2015-06-21 13:39 UTC
From: richard at roguewavelimited dot com Assigned: cmb (profile)
Status: Not a bug Package: *General Issues
PHP Version: 5.5.25 OS: Mac OS X
Private report: No CVE-ID: None
 [2015-06-11 14:09 UTC] richard at roguewavelimited dot com
Description:
------------
Using a tab delimiter with fgetcsv, if the last field of a row is empty, then that field is not included in the returned fields. (Actually in my tests, there can be any number of tabs following the last non-empty data field and all will be ignored.)

For example:

Correct:
1<tab>2<tab>3

returns
array("1","2","3")

Wrong:
1<tab>2<tab>

returns
array("1","2")

should be returned as
array("1","2","")

If you perform this same test using commas as delimiters it works as expected.


Test script:
---------------
Paste this into a new file (be sure to include the trailing tab):

T17492-RB	"Delta Faucets"     

Change the data file name and run this script.
The echo should show 3 but shows 2

$fh = fopen('the_data_file','r');
$fields = fgetcsv($fh, 999999, "\t", '"', "\\");
echo (count($fields));


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-11 18:30 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2015-06-11 18:30 UTC] cmb@php.net
I can't reproduce the described behavior: <http://3v4l.org/c2coK>.
Please run this script on your system, and report the results.
 [2015-06-21 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.
 [2015-06-21 13:28 UTC] richard at roguewavelimited dot com
The issue was reported in error.  Apparently this action was due to the editor that I was using to edit the data file which changed any trailing tabs to spaces.
 [2015-06-21 13:39 UTC] cmb@php.net
-Status: No Feedback +Status: Not a bug
 [2015-06-21 13:39 UTC] cmb@php.net
Thanks for the feedback. :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 18:01:31 2024 UTC