<?php
$srt = <<<SRT
1
00:00:12,759 --> 00:00:17,458
"some content here "
that continues here
2
00:00:18,298 --> 00:00:20,926
here we go again...
3
00:00:21,368 --> 00:00:24,565
...and this can go forever...
SRT;
$lines = explode("\r\n", $srt); // simulate file()
$state = 0;
$blocks = array();
foreach($lines as $line)
{
switch($state)
{
case 0:
unset($block);
$block = array();
$blocks[] = &$block;
$block['number'] = $line;
$state = 1;
break;
case 1:
$block['range'] = $line;
$state = 2;
break;
case 2:
$block['text'] = '';
$state = 3;
# fall-through intended
case 3:
if ($line === '') {
$state = 0;
break;
}
$block['text'] .= ($block['text'] ? "\n" : '') . $line;
break;
default:
throw new Exception(sprintf('Unhandled %d.', $state));
}
}
unset($block);
print_r($blocks);