Advertisement
Filkolev

Message Decoder - fixed

Dec 25th, 2014
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1. <?php
  2. $input = json_decode($_GET['jsonTable']);
  3. $numberOfCols = $input[0];
  4. $messages = $input[1];
  5.  
  6. $pattern = "/Reply from \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}: bytes=\d+ time=(\d+)ms TTL=\d+/";
  7. $string = "";
  8.  
  9. for ($i = 1; $i < count($messages); $i++) {
  10.     preg_match_all($pattern, $messages[$i], $milliseconds);
  11.     $string .= chr($milliseconds[1][0]);
  12. }
  13.  
  14. $result = "<table border='1' cellpadding='5'>";
  15. $index = 0;
  16.  
  17. while ($index < strlen($string)) {
  18.     $result .= "<tr>";
  19.     $lineEnded = false;
  20.  
  21.     for ($col = 0; $col < $numberOfCols; $col++) {
  22.         if ($index >= strlen($string) || $lineEnded) {
  23.             $result .= "<td></td>";
  24.         }
  25.         else if ($string[$index] == "*") {
  26.             if ($col != 0) {
  27.                 $result .= "<td></td>";
  28.                 $lineEnded = true;
  29.             }
  30.             else {
  31.                 $col--;
  32.             }
  33.            
  34.             $index++;
  35.         }
  36.         else if (!ctype_space($string[$index])) {
  37.             $result .= "<td style='background:#CAF'>" . htmlspecialchars($string[$index]) ."</td>";
  38.             $index++;
  39.         }
  40.         else {
  41.             $result .= "<td></td>";
  42.             $index++;
  43.         }
  44.     }
  45.  
  46.     $result .= "</tr>";
  47. }
  48.  
  49. $result .= "</table>";
  50. echo $result;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement