Skip to main content
Version: Fegg 5.x

Csv::parseFile

Read a CSV file

Description​

public static array Csv::parseFile( string $path [, array $options = array() ] )

Reads the file and returns its rows as parse() does; error messages start with the path.

Throws \RuntimeException when the file cannot be read or a row is broken.

Arguments​

NameData typeDefaultRemarks
$pathstringPath of the file
$optionsarrayarray()header, columns, encoding: see parse()

Example​

Controller
use Fegg\Tool\Csv;

$shops = Csv::parseFile(FEGG_SITE_DIR . '/config/shops.csv', array('header' => true));

foreach ($shops as $line => $shop) {
// $shop['店名'], $shop['住所'] ...
}

For a file sent from a form, use parseUpload().