這種模式將工作:
$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:54220 - > 00:00:58350 此外,我敢肯定,Storytown村 也是大家的樂趣... )
[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}')");
}
歡迎來到StackOverflow。你到目前爲止嘗試過哪些方法無效? –
謝謝Ken,我不是一個編碼員(我可以操作基本的東西,但沒有更多),所以我一直在做一些我不完全瞭解的東西的谷歌複製粘貼。這完全逃脫了我 - 太多移動部件,我拼命拼湊在一起。所以我承認失敗並尋求幫助:) – Justin