Skip to content

Instantly share code, notes, and snippets.

@beyondlimits
Last active February 14, 2018 12:08
Show Gist options
  • Save beyondlimits/dbeea04bb5ae21dea91a558b12a753c0 to your computer and use it in GitHub Desktop.
Save beyondlimits/dbeea04bb5ae21dea91a558b12a753c0 to your computer and use it in GitHub Desktop.
<?php
function hexdump($data, $line = 16, $pos = 0)
{
$pad = $line * 3;
foreach (str_split($data, $line) as $chunk) {
$hex = implode(' ', str_split(bin2hex($chunk), 2));
$ascii = preg_replace('/[^\x20-\x7E]/', '.', $chunk);
printf("%04x: %-{$pad}s |%-{$line}s|\n", $pos, $hex, $ascii);
$pos += $line;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment