A simple PHP reading CSV file method

1. The idea: to open a file, read the file number of the line, then read line by line data into an array

public function read_csv_lines($csv_file = '', $lines = 0, $offset = 0)
{
if (!$fp = fopen($csv_file, 'r')) { return false; } $i = $j = 0; while (false !== ($line = fgets($fp))) { if ($i++ < $offset) { continue; } break; } $data = array(); while (($j++ < $lines) && !feof($fp)) { $data[] = fgetcsv($fp); } fclose($fp); return $data; }

 

Guess you like

Origin www.cnblogs.com/jingmin/p/10981218.html