Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Print binary data as hex string
- * @param string $data
- * @param string $newline
- * @param int $width
- */
- function hexdump($data, $newline = "\n", $width = 16) {
- static $from = '';
- static $to = '';
- static $pad = '.'; # padding for non-visible characters
- if ($from === '') {
- for ($i = 0; $i <= 0xFF; $i++) {
- $from .= chr($i);
- $to .= ($i >= 0x20 && $i <= 0x7E) ? chr($i) : $pad;
- }
- }
- $hex = str_split(bin2hex($data), $width * 2);
- $chars = str_split(strtr($data, $from, $to), $width);
- $offset = 0;
- foreach ($hex as $i => $line) {
- echo sprintf('%06X', $offset) . ' : ' . str_pad(implode(' ', str_split($line, 2)), $width * 3) . ' ' . $chars[$i] . $newline;
- $offset += $width;
- }
- }
Add Comment
Please, Sign In to add comment