The bin2hex() function converts a string of ASCII characters to hexadecimal values. The string can be converted back using the pack() function.
bin2hex()函数的作用是:将二进制数据转换成十六进制表示。同时,如果需要转换回原来的进制,那么可以使用pack()函数。
bin2hex(string) |
| Parameter参数 | Description描述 |
|---|---|
| string | Required. The string to be converted 必要参数。指定需要转换的字符串 |
In this example we will convert a string value from binary to hex and back:
在下面的案例中,我们将把一个字符串的值从2进制转换成16进制:
<?php$str = "Hello world!";echo bin2hex($str) . "<br />";echo pack("H*",bin2hex($str)) . "<br />";?> |
The output of the code above will be:
上述代码将输出下面的结果:
48656c6c6f20776f726c6421Hello world! |