fork download
  1. <?php
  2.  
  3. $arr = array(
  4. "2013-06-12 11:25:44 [INFO] There are no objectives on the scoreboard",
  5. "2013-06-12 11:42:27 [INFO] [Server] Hi, how are you?",
  6. "2013-06-12 11:43:40 [INFO] Usage: /scoreboard objectives <list|add|remove|setdisplay>",
  7. "2013-06-12 11:57:51 [INFO] /scoreboard objectives add <name> <criteriaType> [display name ...]",
  8. "2013-06-12 11:57:59 [INFO] Added new objective 'test' successfully",
  9. "2013-06-12 11:58:16 [INFO] Showing 3 objective(s) on scoreboard",
  10. "2013-06-12 11:58:16 [INFO] - test: displays as 'test' and is type 'dummy'",
  11. "2013-06-12 11:58:16 [INFO] - anothertest: displays as 'anothertest' and is type 'dummy'",
  12. "2013-06-12 11:58:16 [INFO] - yetanothertest: displays as 'yetanothertestwithanothername' and is type 'dummy'",
  13. "2013-06-12 11:58:16 [INFO] Showing 4 objective(s) on scoreboard",
  14. "2013-06-12 11:58:16 [INFO] - test: displays as 'test' and is type 'dummy'",
  15. "2013-06-12 11:58:16 [INFO] - anothertest: displays as 'anothertest' and is type 'dummy'",
  16. "2013-06-12 11:58:16 [INFO] - yetanothertest: displays as 'yetanothertestwithanothername' and is type 'dummy'",
  17. "2013-06-12 11:58:17 [INFO] [Server] Dude, stop doing that!",
  18. );
  19.  
  20.  
  21. $datePattern = '\d{4}-\d{2}-\d{2}';
  22. $timePattern = '\d{2}:\d{2}:\d{2}';
  23. $headerPattern = $datePattern . ' ' . $timePattern . ' \[INFO] ';
  24. $showingPattern = $headerPattern
  25. . 'Showing \d+ objective\(s\) on scoreboard';
  26. $messagePattern = $headerPattern
  27. . "- [^:]+: displays as '[^']*' and is type '[^']*'";
  28.  
  29. $results = array();
  30.  
  31. $i = $max = count($arr);
  32. while ($i--) {
  33. $msg = $arr[$i];
  34. if (preg_match("/^$showingPattern/", $msg)) {
  35. $result = array($msg);
  36. for ($j = $i + 1; $j < $max; $j++) {
  37. $nextMsg = $arr[$j];
  38. if (preg_match("/^$messagePattern/", $nextMsg)) {
  39. $result[] = $nextMsg;
  40. }
  41. else {
  42. break;
  43. }
  44. }
  45. $results[$i] = $result;
  46. }
  47. }
  48. var_dump($results);
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
array(2) {
  [9]=>
  array(4) {
    [0]=>
    string(63) "2013-06-12 11:58:16 [INFO] Showing 4 objective(s) on scoreboard"
    [1]=>
    string(73) "2013-06-12 11:58:16 [INFO] - test: displays as 'test' and is type 'dummy'"
    [2]=>
    string(87) "2013-06-12 11:58:16 [INFO] - anothertest: displays as 'anothertest' and is type 'dummy'"
    [3]=>
    string(108) "2013-06-12 11:58:16 [INFO] - yetanothertest: displays as 'yetanothertestwithanothername' and is type 'dummy'"
  }
  [5]=>
  array(4) {
    [0]=>
    string(63) "2013-06-12 11:58:16 [INFO] Showing 3 objective(s) on scoreboard"
    [1]=>
    string(73) "2013-06-12 11:58:16 [INFO] - test: displays as 'test' and is type 'dummy'"
    [2]=>
    string(87) "2013-06-12 11:58:16 [INFO] - anothertest: displays as 'anothertest' and is type 'dummy'"
    [3]=>
    string(108) "2013-06-12 11:58:16 [INFO] - yetanothertest: displays as 'yetanothertestwithanothername' and is type 'dummy'"
  }
}