Advertisement
Filkolev

Message Decoder

Dec 24th, 2014
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 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.             $result .= "<td></td>";
  27.             $index++;
  28.             $lineEnded = true;
  29.         }
  30.         else if (!ctype_space($string[$index])) {
  31.             $result .= "<td style='background:#CAF'>" . htmlspecialchars($string[$index]) ."</td>";
  32.             $index++;
  33.         }
  34.         else {
  35.             $result .= "<td></td>";
  36.             $index++;
  37.         }
  38.     }
  39.  
  40.     $result .= "</tr>";
  41. }
  42.  
  43. $result .= "</table>";
  44. echo $result;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement