/** * Creates a new CSV object from a file. * * @param string $file the filename * @param bool $header whether or not to get the header row * * @return CsvParser a new instance */ public static function fromFile($file, $header = false) { ini_set('auto_detect_line_endings', true); if (true === extension_loaded('mbstring')) { mb_internal_encoding("UTF-8"); } $instance = new self(); if (($handle = fopen($file, "r")) !== false) { $hasHeader = $header; while (($data = fgetcsv($handle, self::LINE_BUFFER_SIZE, self::DELIMITER)) !== false) { // Skip the first row if (true === $hasHeader) { $hasHeader = false; $instance->setHeader($data); continue; } $instance->addRow($data); } fclose($handle); } return $instance; }