static function dumpStringAsHex(string $string, int $width = self::DEFAULT_HEX_WIDTH): string
    {
        static $from = '';
        static $to = '';

        if ($from === '') {
            for ($i = 0; $i <= 0xFF; $i++) {
                $from .= chr($i);
                $to .= ($i >= 0x20 && $i <= 0x7E) ? chr($i) : '.';
            }
        }

        $hex = str_split(bin2hex($string), $width * 2);
        $chars = str_split(strtr($string, $from, $to), $width);

        $hexLineLength = $width * 2 + $width - 1;

        $offset = 0;
        $output = '';
        foreach ($hex as $i => $line) {
            if ($i > 0) {
                $output .= "\n";
            }
            $output .= sprintf('%6X', $offset) . ' : ' . str_pad(implode(' ', str_split($line, 2)), $hexLineLength) . ' [' . $chars[$i] . ']';
            $offset += $width;
        }

        return $output;
    }
static function dumpStringAsHex(string $string, int $width = self::DEFAULT_HEX_WIDTH): string
    {
        static $from = '';
        static $to = '';

        if ($from === '') {
            for ($i = 0; $i <= 0xFF; $i++) {
                $from .= chr($i);
                $to .= ($i >= 0x20 && $i <= 0x7E) ? chr($i) : '.';
            }
        }

        $hex = str_split(bin2hex($string), $width * 2);
        $chars = str_split(strtr($string, $from, $to), $width);

        $hexLineLength = $width * 2 + $width - 1;

        $offset = 0;
        $output = '';
        foreach ($hex as $i => $line) {
            if ($i > 0) {
                $output .= "\n";
            }
            $output .= sprintf('%6X', $offset) . ' : ' . str_pad(implode(' ', str_split($line, 2)), $hexLineLength) . ' [' . $chars[$i] . ']';
            $offset += $width;
        }

        return $output;
    }
static function dumpStringAsHex ( string $ string , int $ width = self :: DEFAULT_HEX_WIDTH ) : string { static $ from = '' ; static $ to = '' ; if ( $ from === '' ) { for ( $ i = 0 ; $ i <= 0xFF ; $ i ++ ) { $ from .= chr ( $ i ) ; $ to .= ( $ i >= 0x20 && $ i <= 0x7E ) ? chr ( $ i ) : '.' ; } } $ hex = str_split ( bin2hex ( $ string ) , $ width * 2 ) ; $ chars = str_split ( strtr ( $ string , $ from , $ to ) , $ width ) ; $ hexLineLength = $ width * 2 + $ width - 1 ; $ offset = 0 ; $ output = '' ; foreach ( $ hex as $ i => $ line ) { if ( $ i > 0 ) { $ output .= "\n" ; } $ output .= sprintf ( '%6X' , $ offset ) . ' : ' . str_pad ( implode ( ' ' , str_split ( $ line , 2 ) ) , $ hexLineLength ) . ' [' . $ chars [ $ i ] . ']' ; $ offset += $ width ; } return $ output ; }
Dump a string in HEX format
Dump a string in HEX format