Created
February 16, 2016 00:24
-
-
Save kurozumi/6485b363f974ebfeae93 to your computer and use it in GitHub Desktop.
【CodeIgniter3】league/csvを使ってCSVファイルを読み込む方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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