Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function hexdump($string) {
- $data = array();
- foreach (str_split($string, 16) as $line) {
- $data[] = str_split($line);
- }
- $output = "00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF";
- $linecount = 0;
- foreach ($data as $datum) {
- ++$linecount;
- $line = str_repeat(" ", 68);
- for ($i = 0; $i < count($datum); ++$i) {
- if (empty($datum[$i])) {
- break 2;
- }
- $chr = $datum[$i];
- $pos = $i * 3 + ( $i > 7 ? 2 : 0 );
- $hex = sprintf('%02X', ord($chr));
- $line[$pos] = $hex[0];
- $line[$pos + 1] = $hex[1];
- $line[68 - 16 + $i] = ($chr >= ' ' && $chr <= 'z' ? $chr : '.');
- }
- $output .= "\n$line";
- }
- $maxlen = max(2, strlen($linecount - 1));
- $output = explode("\n", $output);
- for ($i = 1; $i < count($output); ++$i) {
- $output[$i] = sprintf("%0{$maxlen}X %s", $i - 1, $output[$i]);
- }
- return "-- " . implode("\n", $output);
- }
Add Comment
Please, Sign In to add comment