Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.0.0

Bug #15233 discoverFormat finds wrong separator
Submitted: 2008-12-04 15:01 UTC
From: brafreider Assigned: dufuz
Status: Closed Package: File_CSV (version 1.0.0alpha1)
PHP Version: Irrelevant OS: linux (irrelevant)
Roadmaps: (Not assigned)    

 [2008-12-04 15:01 UTC] brafreider (Björn Rafreider)
Description: ------------ If I read a CSV with one line that contains ";" as separators and "," in unquoted fields, discoverformat() sets "," as separator. This will eqaully happen if you have a CSV with at least one "," in every line, as $amount will have the same line count for the two separators. I have done a workaround if $amount[0]==$amount[1] after the arsort($amount) CSV.php; line 558ff: $final = array(); $max = array(); // Group the results by amount of equal ocurrences foreach ($matches as $sep => $res) { $times = array(); $times[0] = 0; foreach ($res as $k => $num) { if ($num > 0) { $times[$num] = (isset($times[$num])) ? $times[$num] + 1 : 1; } $max[$sep] = ($num > $max[$sep])?$num:$max[$sep]; } arsort($times); // Use max fields count. $fields[$sep] = max(array_flip($times)); $amount[$sep] = $times[key($times)]; } arsort($amount); arsort($max); if ($amount[0] > $amount[1]){ $sep = key($amount); }else{ $sep = key($max); }


 [2008-12-06 11:26 UTC] doconnor (Daniel O'Connor)
I don't suppose you could whip up a small executable test case, Bjorn?
 [2009-03-13 03:06 UTC] dufuz (Helgi Þormar Þorbjörnsson)
-Status: Open +Status: Feedback
We are unable to reproduce the bug as reported. Please provide a simple script (10 lines or less) or a link to an external script that can be used to reproduce the bug. If you can provide the script, feel free to add it to this bug and change the status back to "Open". Thank you for your interest in PEAR.
 [2010-04-29 06:57 UTC] dufuz (Helgi Þormar Þorbjörnsson)
Would it be possible to get an example CSV, please?
 [2010-04-29 06:57 UTC] dufuz (Helgi Þormar Þorbjörnsson)
-Assigned To: +Assigned To: dufuz
 [2010-04-29 12:40 UTC] brafreider (Björn Rafreider)
Hi Helgi, I´m sorry but I did not get the answers until today... It´s kind of long time ago, I remember that there was a bug, but I don´t know under which circumstances... Sorry Björn
 [2011-03-15 07:00 UTC] dufuz (Helgi Þormar Þorbjörnsson)
-Status: Feedback +Status: Closed
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on by the end of next Sunday (CET). If this was a problem with the website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better. The fix I came up with depends on the separator to have more occurrences than the comma. Logically one would have quotes around text containing spaces or potential separators to prevent such detection from happening, that's one way to bypass this problem.