怎么样:
$string = '[9] 20:30:40 [SUCCESS] s-a24:1337
2
8.87
4038047
35320
4002727
[10] 20:30:40 [SUCCESS] s-d28:1337
2
2.64
4038047
37363
4000684
[11] 20:30:40 [SUCCESS] s-b29:1337
2
0.56
4038047
33066
4004981
[66] 20:30:42 [FAILURE] s-b25:1337 Timed out, Killed by signal 9
2
1.16
4038047
35274
[67] 20:30:42 [FAILURE] s-b30:1337 Timed out, Killed by signal 9
';
preg_match_all("/\[.*?\[(SUCCESS|FAILURE)\]\s+([^:]+):[^\n]+\n(?:([^[]+?)\n)?(?:([^[]+?)\n)?(?:([^[]+?)\n)?(?:([^[]+?)\n)?(?:([^[]+?)\n)?/m", $string, $matches, PREG_SET_ORDER);
print_r($matches);
输出:
Array
(
[0] => Array
(
[0] => [9] 20:30:40 [SUCCESS] s-a24:1337
2
8.87
4038047
35320
4002727
[1] => SUCCESS
[2] => s-a24
[3] => 2
[4] => 8.87
[5] => 4038047
[6] => 35320
[7] => 4002727
)
[1] => Array
(
[0] => [10] 20:30:40 [SUCCESS] s-d28:1337
2
2.64
4038047
37363
4000684
[1] => SUCCESS
[2] => s-d28
[3] => 2
[4] => 2.64
[5] => 4038047
[6] => 37363
[7] => 4000684
)
[2] => Array
(
[0] => [11] 20:30:40 [SUCCESS] s-b29:1337
2
0.56
4038047
33066
4004981
[1] => SUCCESS
[2] => s-b29
[3] => 2
[4] => 0.56
[5] => 4038047
[6] => 33066
[7] => 4004981
)
[3] => Array
(
[0] => [66] 20:30:42 [FAILURE] s-b25:1337 Timed out, Killed by signal 9
2
1.16
4038047
35274
[1] => FAILURE
[2] => s-b25
[3] => 2
[4] => 1.16
[5] => 4038047
[6] => 35274
)
[4] => Array
(
[0] => [67] 20:30:42 [FAILURE] s-b30:1337 Timed out, Killed by signal 9
[1] => FAILURE
[2] => s-b30
)
)