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

后端 未结 10 945
后悔当初
后悔当初 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:18

    CSV rows are separated by line breaks. Therefore, split the rows by line breaks, and you will get an array of rows, which is countable.

    if (($fp = fopen("test.csv", "r")) !== FALSE) { 
        $rows = explode("\n", $fp);
        $length = count($rows);
    
        echo $length;
    }
    

提交回复
热议问题