Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
【CodeIgniter3】league/csvを使ってCSVファイルを読み込む方法
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
use League\Csv\Reader;
class Welcome extends CI_Controller {
public function load_csv()
{
$csv = Reader::createFromPath(APPPATH . "../csv/file.csv");
// ヘッダーを取得
$headers = $csv->fetchOne();
var_dump($headers);
// 先頭から10行取得
$res = $csv->setLimit(10)->fetchAll();
var_dump($res);
// 5行目から10行取得
$res = $csv->setOffset(4)->setLimit(10)->fetchAll();
var_dump($res);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment