【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