Advertisement
Guest User

functions.php

a guest
Nov 13th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. <?php
  2.  
  3. // Helper functions
  4.  
  5. function hex_dump($data, $newline="\n")
  6. {
  7.   static $from = '';
  8.   static $to = '';
  9.  
  10.   static $width = 16; # number of bytes per line
  11.  
  12.   static $pad = '.'; # padding for non-visible characters
  13.  
  14.   if ($from==='')
  15.   {
  16.     for ($i=0; $i<=0xFF; $i++)
  17.     {
  18.       $from .= chr($i);
  19.       $to .= ($i >= 0x20 && $i <= 0x7E) ? chr($i) : $pad;
  20.     }
  21.   }
  22.  
  23.   $hex = str_split(bin2hex($data), $width*2);
  24.   $chars = str_split(strtr($data, $from, $to), $width);
  25.  
  26.   $offset = 0;
  27.   foreach ($hex as $i => $line)
  28.   {
  29.     echo sprintf('%6X',$offset).' : '.implode(' ', str_split($line,2)) . ' [' . $chars[$i] . ']' . $newline;
  30.     $offset += $width;
  31.   }
  32. }
  33.  
  34.  
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement