How can I get a hex dump of a string in PHP?

后端 未结 6 1132
陌清茗
陌清茗 2020-11-22 07:50

I\'m investigating encodings in PHP5. Is there some way to get a raw hex dump of a string? i.e. a hex representation of each of the bytes (not characters) in a string?

6条回答
  •  礼貌的吻别
    2020-11-22 08:29

        echo implode(array_map(
            fn ($a, $b) => sprintf("%-26s%-8s\n", $a, $b), 
            str_split(implode(' ', str_split(bin2hex($string), 2)), 24),
            str_split($string, 8)
        ));
    

提交回复
热议问题