Advertisement
cgrunwald

Untitled

Jan 5th, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.57 KB | None | 0 0
  1.     protected function parse( $text )
  2.     {
  3.         // Parse out the times and then split by them.
  4.         preg_match_all('/\d{4}-\d\d-\d\d\ (\d\d:\d\d:\d\d)\ ---\ /mx', $text, $times, PREG_PATTERN_ORDER);
  5.         $times = $times[1];
  6.         $lines = preg_split('/\d{4}-\d\d-\d\d\ \d\d:\d\d:\d\d\ ---\ /mx', $text);
  7.         $lines = array_slice( $lines, 1 );
  8.         $log = array();
  9.         foreach($lines as $i => $line) {
  10.             if (preg_match('/^(\w+): (.+)$/sm', $line, $s_parts)) {
  11.                 $header = $s_parts[1];
  12.                 $details = trim($s_parts[2]);
  13.                 if (preg_match('/^([a-z_\-]+) ?(?:\[ ?(\-?\d+) ?\])?: ?(.*)$/si', $details, $s_parts)) {
  14.                     $details = '<div class="class">' . $s_parts[1];
  15.                     $details .= empty($s_parts[2]) ? '</div>' : ' (' . $s_parts[2] . ')</div>';
  16.                     if (preg_match('/^(.*) \[ ?(\d+) ?\]$/s', $s_parts[3], $s_details)) {
  17.                         $details .= "\n<p>" . $s_details[1] . "</p>";
  18.                         $details .= "\n<p style=\"text-align:right;font-weight:bold;margin-bottom:0;\">(Line #" . $s_details[2] . ")</strong>";
  19.                     } else {
  20.                         $details .= "\n<p>" . $s_parts[3] . "</p>";
  21.                     }
  22.                 } else {
  23.                     if (preg_match('/^(.*) \[ ?(\d+) ?\]$/s', $details, $s_parts)) {
  24.                         $details .= "\n<p>" . $s_parts[1] . "</p>";
  25.                         $details .= "\n<p style=\"text-align:right;font-weight:bold;\">(Line #" . $s_parts[2] . ")</strong>";
  26.                     }
  27.                 }
  28.                 array_push($log, array(
  29.                     // Set the time.
  30.                     'time' => date("g:i:s A", strtotime($times[$i])),
  31.                     // Then the header.
  32.                     'header' => $header,
  33.                     // And finally, the details.
  34.                     'details' => $details,
  35.                 ));
  36.             }
  37.         }
  38.  
  39.         return  View::factory('console/entry')->set('log', $log)->render();
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement