1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CSVでファイルを取り込んで正規表現をかけて結果を出力する

Posted at

簡単だけど結構ハマったのでメモ。

▼サンプルコード
//ファイルの読み込み
$string=file_get_contents("sample.log");

//正規表現検索
preg_match_all("/\d{4}-\d{2}-\d{2}\t\d{2}:\d{2}:\d{2}/", $string, $match);

var_dump($match);

==========================================
▼CSV
以下のようなデータ。



TestNo: 1.0
Date: 2017-09-29
2017-09-29 10:50:14 * 合格点 = 50
2017-09-29 10:50:14 24480 (a)1234567 [INFO] 得点 = 50 -
2017-09-29 10:50:14 24480 (c)0099322 [INFO] 合否フラグ = ture -
2017-09-29 10:50:14 24480 (b)7777777 [INFO] 得点 = 30 -
2017-09-29 10:50:14 24480 (c)0099322 [INFO] 合否フラグ = false -

==========================================
▼出力結果
array(1) {
[0] =>
array(20) {
[0] =>
string(19) "2017-09-29 10:50:14"
[1] =>
string(19) "2017-09-29 10:50:14"
[2] =>
string(19) "2017-09-29 10:50:14"
[3] =>
string(19) "2017-09-29 10:50:14"
[4] =>
string(19) "2017-09-29 10:50:14"
[5] =>
string(19) "2017-09-29 10:50:14"
[6] =>
string(19) "2017-09-29 10:50:14"
[7] =>
string(19) "2017-09-29 10:50:14"
[8] =>
string(19) "2017-09-29 10:50:14"
[9] =>
string(19) "2017-09-29 10:50:14"
[10] =>
string(19) "2017-09-29 10:50:14"
[11] =>
string(19) "2017-09-29 10:50:14"
[12] =>
string(19) "2017-09-29 10:50:14"
[13] =>
string(19) "2017-09-29 10:50:14"
[14] =>
string(19) "2017-09-29 10:50:14"
[15] =>
string(19) "2017-09-29 10:50:14"
[16] =>
string(19) "2017-09-29 10:50:14"
[17] =>
string(19) "2017-09-29 10:50:14"
[18] =>
string(19) "2017-09-29 10:50:14"
[19] =>
string(19) "2017-09-29 10:50:14"
}
}

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?