How can I get the total number of rows in a CSV file with PHP?

后端 未结 10 909
后悔当初
后悔当初 2020-12-05 22:35

How can I get the total number of rows that are in a CSV file using PHP? I\'m using this method but can get it to work properly.

if (($fp = fopen(\"test.csv\         


        
10条回答
  •  时光取名叫无心
    2020-12-05 23:26

    I know that this is pretty old, but actually I ran into the same question. As a solution I would assume to use linux specific logic:

    $rows = shell_exec('$(/bin/which cat) file.csv | $(/bin/which tr) "\r" "\n" | $(which wc) -l');
    

    NOTE: this only works for linux only and this only should be used if you are 100% certain that your file has no multiline-cells

提交回复
热议问题