PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » File System » File » Bug #2827

File_CSV::discoverFormat() is unable to discover format in one column CSV file

Details

Submitted2004-11-25 11:27 UTC
Fromjocke at selincite dot com
Assigneddufuz
StatusClosed
PackageFile
PHP Version4.3.8
OSLinux
Roadmaps1.3.0a1

Comments

[2004-11-25 11:27 UTC] jocke at selincite dot com

Description:
------------
We're using File_CSV to parse and store imported CSV data. This works fine except for when the CSV file only contains one column, such as
===
a@b.com
c@d.net
e@f.org
===
When using File_CSV::discoverFormat(), the following warning is issued:
===
Warning: Could not discover the separator in /var/www/html/PEAR/PEAR.php on line 762
===
The reason for this is obviously that the file doesn't contain any separator character, however the file is still a completely valid CSV file (AFAIK).

Thanks!

Reproduce code:
---------------
Save
===
a@b.com
c@d.net
e@f.org
===
to a file, say /tmp/onecol.csv and run the following code:

===
$aConfig = File_CSV::discoverFormat("/tmp/onecol.csv");
===

Expected result:
----------------
$aConfig to be

Array
(
[fields] => 1,
[sep] => NULL,
[quote] => NULL
)

Or some other format that aids the next method used (typically: File_CSV::read())

Actual result:
--------------
Pear warning:
Warning: Could not discover the separator in /var/www/html/PEAR/PEAR.php on line 762

[2004-11-29 11:40 UTC] jocke at selincite dot com

Hi,

I've 'fixed' the problem by commenting the if-statement that generates the error message. This seems to work fine on our system, but I'm sure that someone can fix a much more elegant solution to this problem. I'm pasting the diff here; it might help someone resolve the problem temporarily, and hopefully a developer might be able to use it as a starting-point for a better solution.

Cheers,

/JS

Patch for CSV.php
===
385,388c385,387
< // This if-statement generates error when reading a one-column CSV file
< // if (empty($fields)) {
< // return File_CSV::raiseError('Could not discover the separator');
< // }
---
> if (empty($fields)) {
> return File_CSV::raiseError('Could not discover the separator');
> }
===