这种模式会起作用:
$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 我觉得很高兴我们正在做一些 Maggie 会喜欢的事情。[2] => 00:00:54,220 --> 00:00:58,350 此外,我相信 Storytown Village 对每个人来说也很有趣......)
[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}')");
}