PHPで複雑なCSVを読み込みたい
大証が毎日提供している日経先物のcsvファイルを読み込んで、データベース化したいなと思っています。
下記のようなcsvです。
--------------------------------------------
"日経225先物取引"
"限月","取引最終日","コード","約定指数",,,,,"前日比較","最終気配","取引高概算","清算指数","建玉残高概算"
,,,,"始値","高値","安値","終値"
,,,,"円","円","円","円","円","円","単位","円","単位"
"19年 6月"," 6. 7","162060018"," ","… ","… ","… ","… ","…"," …","… ","17912.59","230446"
" "," ","(SP)"," "," "," "," "," "," "," ","(…)"," "," "
"19年 9月"," 9.13","162090018"," ","17880 ","17890 ","17720 ","17790 ","-310"," …","135069 ","17790.00","270392"
" "," ","(SP)"," "," "," "," "," "," "," ","(…)"," "," "
" "," ","(立会外)"," ","(18057)","(18057)","(17750)","(17807)"," "," ","(11843)"," "," "
"19年 12月","12.13","162120018"," ","17870 ","17870 ","17710 ","17770 ","-270"," …","315 ","17770.00","5903"
" "," ","(SP)"," "," "," "," "," "," "," ","(…)"," "," "
"20年 3月"," 3.13","163030018"," ","17840 ","17860 ","17760 ","17790 ","-290"," …","9 ","17786.88","3931"
" "," ","(SP)"," "," "," "," "," "," "," ","(…)"," "," "
"20年 6月"," 6.12","163060018"," ","17850 ","17850 ","17700 ","17740 ","-300"," …","28 ","17735.58","1322"
" "," ","(SP)"," "," "," "," "," "," "," ","(…)"," "," "
"20年 9月"," 9.11","163090018"," ","17840 ","17840 ","17840 ","17840 ","…"," …","1 ","17760.52","1"
" "," ","(SP)"," "," "," "," "," "," "," ","(…)"," "," "
"平均株価"," ","日経225","","17904.68","17904.68","17696.51","17779.09","-274.29"," …","… ","…","…"
---------------------------------------------------
かなりごちゃごちゃですが、このようなcsvです。
例えばこのcsvから19年6月のデータだけ取得したい場合、
どのようなソースを書けばよいのでしょうか。
自分なりに考えてみたのですが、
19年6月は3行あります。SPとか立会外は不要ですので、つまり
"19年 9月"," 9.13","162090018"," ","17880 ","17890 ","17720 ","17790 ","-310"," …","135069 ","17790.00","270392"
この部分のみ必要です。
まずcsvを読み込み"19年 9月"を検索し、該当の行だけを抜くような形かな?と思っています。
よろしくお願いします。
お礼
この方法で成功しましたので、ポイント付与させていただきます。 ありがとうございました。