function ReadCsv($file) { $csv = new splfileobject($file); $csv->setFlags(SplFileObject::READ_CSV); $dumplist = array(); $userlist = array(); foreach ($csv as $row) { array_push($dumplist, $row); } array_shift($dumplist); // 列名の行は削除 foreach ($dumplist as $row) { @($user_id = $row[0]); @($last_artwork_id = $row[1]); @($display_name = $row[2]); // Error Cacht if (empty($user_id) != true) { // 空じゃないとき if (@preg_grep('/^\\d+$/', $user_id)) { // user_idは数字だけのときだけ許す Msg("error", "user_id is only digit.\n"); exit(1); } if (@preg_grep('/^\\d+$/', $last_artwork_id)) { // last_artwork_idは数字だけ Msg("error", "last_artwork_id is only digit.\n"); exit(1); } $user = array('user_id' => $user_id, 'last_artwork_id' => $last_artwork_id, 'display_name' => $display_name); array_push($userlist, $user); } // 先頭が空の時は無視する } Msg('succeed', "Read csv file '" . $file . "'.\n"); return $userlist; }
<?php $x = new splfileobject(__FILE__); $x->getPathName(); $x->seek(10); $x->seek(0); var_dump(trim($x->fgets()));