Bug #69800 [NEW]: fgetcsv ignores empty trailing field with tab delimiter
| From: | richard at roguewavelimited dot com | Date: | Thu, 11 Jun 2015 14:09:02 +0000 |
| Subject: | Bug #69800 [NEW]: fgetcsv ignores empty trailing field with tab delimiter | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-193329@lists.php.net to get a copy of this message | ||
From: richard at roguewavelimited dot com
Operating system: Mac OS X
PHP version: 5.5.25
Package: *General Issues
Bug Type: Bug
Bug description:fgetcsv ignores empty trailing field with tab delimiter
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 bug report at https://bugs.php.net/bug.php?id=69800&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69800&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69800&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69800&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69800&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69800&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69800&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69800&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69800&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69800&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69800&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69800&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69800&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69800&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69800&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69800&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69800&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69800&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69800&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69800&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69800&r=mysqlcfg