FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=15233&edit=1

ID: 15233
Updated by: helgith@gmail.com
Reported By: bs at visual4 dot de
Summary: discoverFormat finds wrong separator
Status: Feedback
Type: Bug
Package: File_CSV
Operating System: linux (irrelevant)
Package Version: 1.0.0alpha1
PHP Version: Irrelevant
Roadmap Versions:
New Comment:

Would it be possible to get an example CSV, please?


Previous Comments:
------------------------------------------------------------------------

[2009-03-12 23:06:40] dufuz

-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.

------------------------------------------------------------------------

[2008-12-06 06:26:21] doconnor

I don't suppose you could whip up a small executable test case, Bjorn?

------------------------------------------------------------------------

[2008-12-04 10:01:35] brafreider

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);
}

------------------------------------------------------------------------

Search Discussions

  • Helgith at Apr 29, 2010 at 2:03 am
    Edit report at http://pear.php.net/bugs/bug.php?id=15233&edit=1

    ID: 15233
    Updated by: helgith@gmail.com
    Reported By: bs at visual4 dot de
    Summary: discoverFormat finds wrong separator
    Status: Feedback
    Type: Bug
    Package: File_CSV
    Operating System: linux (irrelevant)
    Package Version: 1.0.0alpha1
    PHP Version: Irrelevant
    -Assigned To:
    +Assigned To: dufuz
    Roadmap Versions:
    New Comment:

    -Assigned To:
    +Assigned To: dufuz



    Previous Comments:
    ------------------------------------------------------------------------

    [2010-04-29 02:57:16] dufuz

    Would it be possible to get an example CSV, please?

    ------------------------------------------------------------------------

    [2009-03-12 23:06:40] dufuz

    -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.

    ------------------------------------------------------------------------

    [2008-12-06 06:26:21] doconnor

    I don't suppose you could whip up a small executable test case, Bjorn?

    ------------------------------------------------------------------------

    [2008-12-04 10:01:35] brafreider

    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);
    }

    ------------------------------------------------------------------------
  • Bs at Apr 29, 2010 at 7:46 am
    Edit report at http://pear.php.net/bugs/bug.php?id=15233&edit=1

    ID: 15233
    Updated by: bs@visual4.de
    Reported By: bs at visual4 dot de
    Summary: discoverFormat finds wrong separator
    Status: Feedback
    Type: Bug
    Package: File_CSV
    Operating System: linux (irrelevant)
    Package Version: 1.0.0alpha1
    PHP Version: Irrelevant
    Assigned To: dufuz
    Roadmap Versions:
    New Comment:

    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


    Previous Comments:
    ------------------------------------------------------------------------

    [2010-04-29 02:57:20] dufuz

    -Assigned To:
    +Assigned To: dufuz


    ------------------------------------------------------------------------

    [2010-04-29 02:57:16] dufuz

    Would it be possible to get an example CSV, please?

    ------------------------------------------------------------------------

    [2009-03-12 23:06:40] dufuz

    -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.

    ------------------------------------------------------------------------

    [2008-12-06 06:26:21] doconnor

    I don't suppose you could whip up a small executable test case, Bjorn?

    ------------------------------------------------------------------------

    [2008-12-04 10:01:35] brafreider

    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);
    }

    ------------------------------------------------------------------------

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedApr 29, '10 at 2:03a
activeApr 29, '10 at 7:46a
posts3
users2
websitepear.php.net

2 users in discussion

Helgith: 2 posts Bs: 1 post

People

Translate

site design / logo © 2022 Grokbase