Advertisement
Aleksiev

PHP Exam - Error Logger

Sep 5th, 2014
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. <?php
  2.  
  3. $text = trim($_GET['errorLog']);
  4.  
  5. $lines = explode('Exception in thread', $text);
  6.  
  7. $result = '<ul>';
  8. foreach ($lines as $line) {
  9.     if (preg_match('/java\./', $line) && !preg_match('/\(\)/', $line)) {
  10.         $rows = preg_split('/\r?\n/', $line, -1, PREG_SPLIT_NO_EMPTY);
  11.  
  12.         $exc = preg_split('/[\.\:]/', trim($rows[0]));
  13.         $exception = $exc[sizeof($exc) - 2];
  14.  
  15.         for ($i = 1; $i < sizeof($rows); $i++) {
  16.             if (strpos(trim($rows[$i]), 'at ') !== false) {
  17.                 $elements = preg_split('/[\.\(\)\:]/', trim($rows[1]), -1, PREG_SPLIT_NO_EMPTY);
  18.  
  19.                 $row = trim($elements[4]);
  20.                 $file = trim($elements[2]) . '.' . trim($elements[3]);
  21.                 $method = trim($elements[1]);
  22.  
  23.                 $result .= '<li>line <strong>' . htmlspecialchars($row) . '</strong> - <strong>' . htmlspecialchars($exception) . '</strong> in <em>' . htmlspecialchars($file) . ':' . htmlspecialchars($method) . '</em></li>';
  24.                 break;
  25.             }
  26.         }
  27.     }
  28. }
  29. $result .= '</ul>';
  30.  
  31. echo $result;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement