このパターンは機能します:
$pattern = '/([\d,:]+) --> [\d,:]+\n(.*\n.*)[^\n\n]/m';
$string = "
8
00:00:45,879 --> 00:00:50,680
- Oh! Just leave me in the car with the window open a crack.
- That's the plan.
9
00:00:50,784 --> 00:00:54,117
I think it's nice we're doing something
Maggie will enjoy for once.
10
00:00:54,220 --> 00:00:58,350
Besides, I'm sure Storytown Village
is also fun for everyone..."; //Your File Contents Here
preg_match_all($pattern, $string, $matches);
print_r($matches);
これにより、次のようになります。
Array
(
[0] => Array
(
[0] => 00:00:45,879 --> 00:00:50,680
- おー!窓を開けたまま車の中に置いておいてください。-それが計画です。[1] => 00:00:50,784-> 00:00:54,117マギーが一度楽しんでくれることをやっているのはいいことだと思います。[2] => 00:00:54,220-> 00:00:58,350その上、ストーリータウンビレッジもみんなにとって楽しいと思います...)
[1] => Array
(
[0] => 00:00:45,879
[1] => 00:00:50,784
[2] => 00:00:54,220
)
[2] => Array
(
[0] => - Oh! Just leave me in the car with the window open a crack.
- That's the plan
[1] => I think it's nice we're doing something
Maggie will enjoy for once
[2] => Besides, I'm sure Storytown Village
is also fun for everyone..
)
)
アップデート:
foreach($matches[1] as $i => $data){
$time = $data;
$message = $matches[2][$i];
mysqli_query("INSERT INTO Table (time,message) VALUES ('{$time}', '{$message}')");
}