Bug #69800 [Opn->Fbk]: fgetcsv ignores empty trailing field with tab delimiter
| From: | cmb@php.net | Date: | Thu, 11 Jun 2015 18:30:16 +0000 |
| Subject: | Bug #69800 [Opn->Fbk]: fgetcsv ignores empty trailing field with tab delimiter | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-193336@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69800&edit=1
ID: 69800
Updated by: cmb@php.net
Reported by: richard at roguewavelimited dot com
Summary: fgetcsv ignores empty trailing field with tab
delimiter
-Status: Open
+Status: Feedback
Type: Bug
Package: *General Issues
Operating System: Mac OS X
PHP Version: 5.5.25
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
I can't reproduce the described behavior: <http://3v4l.org/c2coK>.
Please run this script on your system, and report the results.
Previous Comments:
------------------------------------------------------------------------
[2015-06-11 14:09:01] 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));
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69800&edit=1