Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Created February 16, 2016 00:24
Show Gist options
  • Save kurozumi/6485b363f974ebfeae93 to your computer and use it in GitHub Desktop.
Save kurozumi/6485b363f974ebfeae93 to your computer and use it in GitHub Desktop.
【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