Advertisement
dimipan80

Message Decoder

May 2nd, 2015
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2. $jsonTable = json_decode($_GET['jsonTable']);
  3. $columns = (int)$jsonTable[0];
  4. $timePattern = '/^\s*Reply\s+from\s+\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\s*\: bytes=\d{1,4}\s+time=\s*(\d+)\s*ms\s+TTL=\d{1,4}\s*$/';
  5.  
  6. $message = '';
  7. for ($i = 1; $i < count($jsonTable[1]); $i++) {
  8.     $ping = $jsonTable[1][$i];
  9.     preg_match($timePattern, $ping, $matches);
  10.     $milliseconds = (int)$matches[1];
  11.     $message .= chr($milliseconds);
  12. }
  13.  
  14. $words = explode('*', $message);
  15. $style = "style='background:#CAF'";
  16. echo '<table border=\'1\' cellpadding=\'5\'>';
  17. foreach ($words as $word) {
  18.     $rows = ceil(strlen($word) / $columns);
  19.     $charCounter = 0;
  20.     for ($i = 0; $i < $rows; $i++) {
  21.         echo '<tr>';
  22.         for ($col = 0; $col < $columns; $col++) {
  23.             if ($charCounter < strlen($word) && $word[$charCounter] != ' ') {
  24.                 echo "<td {$style}>" . htmlspecialchars($word[$charCounter]) . '</td>';
  25.             } else {
  26.                 echo '<td></td>';
  27.             }
  28.             $charCounter++;
  29.         }
  30.         echo '</tr>';
  31.     }
  32. }
  33. echo '</table>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement