Guest User

Untitled

a guest
Feb 19th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Print binary data as hex string
  5. * @param string $data
  6. * @param string $newline
  7. * @param int $width
  8. */
  9. function hexdump($data, $newline = "\n", $width = 16) {
  10. static $from = '';
  11. static $to = '';
  12.  
  13. static $pad = '.'; # padding for non-visible characters
  14.  
  15. if ($from === '') {
  16. for ($i = 0; $i <= 0xFF; $i++) {
  17. $from .= chr($i);
  18. $to .= ($i >= 0x20 && $i <= 0x7E) ? chr($i) : $pad;
  19. }
  20. }
  21.  
  22. $hex = str_split(bin2hex($data), $width * 2);
  23. $chars = str_split(strtr($data, $from, $to), $width);
  24.  
  25. $offset = 0;
  26. foreach ($hex as $i => $line) {
  27. echo sprintf('%06X', $offset) . ' : ' . str_pad(implode(' ', str_split($line, 2)), $width * 3) . ' ' . $chars[$i] . $newline;
  28. $offset += $width;
  29. }
  30. }
Add Comment
Please, Sign In to add comment