O
O
Oleg2017-12-01 23:36:43
PHP
Oleg, 2017-12-01 23:36:43

Wrote a universal csv parser in PHP How many queries should be split optimally?

Small volumes are parsed normally.
But with 4MB it's a long time.

<?php
$file_name="tools.csv";
$fp = fopen($file_name, 'r');
$head = fgetcsv($fp, 4096, ';', '"');

    while($column = fgetcsv($fp, 4096, ';')){   
      $column = array_combine($head, $column);
      $ww[]=$column;
    }

    
    $dd[] = $ww;
    echo"<table><tr>";
        for ($i = 0; $i <count($head); $i++) {
            echo "<th>".$head[$i]."</th>";//Вывод заголовков полей
        }
    echo "</tr>";
    
    foreach ($dd as $key){
      echo"<tr>";
            foreach ($key as $key2) {
                for ($i = 0; $i <count($head); $i++) {
                  echo "<td>".$key2[$head[$i]]. "</td>"; //Вывод строк
                }
                  echo"<tr>";
            }
    }
    echo"</table>";
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
g_s_e, 2017-12-02
@g_s_e

<<<But with 4Mb it takes a long time.
i could be wrong, but the problem could be in this line: specifically in the "=" operator, i think it should be something like, "<=", ">=", etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question