[PHP-BUG] Req #51496 [NEW]: fgetcsv should take empty string as an escape
[email protected] ("kulakov74 at yandex dot ru") Wed, 7 Apr 2010 14:34:19 +0200 (CEST)
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <[email protected]> |
From:
Operating system: All
PHP version: 5.3.2
Package: Filesystem function related
Bug Type: Feature/Change Request
Bug description:fgetcsv should take empty string as an escape
Description:
------------
Currently fgetcsv() gives a warning if the escape parameter is set as an
empty string (and the default is a backslash). I have some data that has
backslashes in it and it's not an escape character. Even though most of the
times fgetcsv() reads the data correctly, there is a little chance it will
do it wrong if a backslash is the last character of a multiline cell, which
is usually stored like this:
"\\\line1
line2\\\"
In order to fix that I supply chr(8) as an escape character because I know
for sure the data does not have the character. And if I pass an empty
string instead fgetcsv() will give a warning and refuse to read a line.
I suggest that fgetcsv() does accept an empty string as an escape and do no
escaping in that case, which is quite usual.
For ex., a MySql statement "Load Data Infile ... Into Table" has it as
"Escaped By None" to achieve the same result.
Test script:
---------------
if (!$Handle=fopen("sites.txt", "rb")) return false;
print_r(fgetcsv($Handle, 0, "\t", '"', ""));
fclose($Handle);
Expected result:
----------------
array( ... ) - depends on the input file
Actual result:
--------------
Warning: fgetcsv(): escape must be character in ...
--
Edit bug report at http://bugs.php.net/bug.php?id=51496&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51496&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51496&r=trysnapshot53
Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=51496&r=trysnapshot60
Fixed in SVN: http://bugs.php.net/fix.php?id=51496&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51496&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=51496&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=51496&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=51496&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=51496&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=51496&r=support
Expected behavior: http://bugs.php.net/fix.php?id=51496&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=51496&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=51496&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=51496&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51496&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=51496&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=51496&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=51496&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=51496&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=51496&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=51496&r=mysqlcfg