把"Hello World!" 轉換為十六進位值:
<?php $str = bin2hex("Hello World!");echo($str); ?>bin2hex() 函數把ASCII 字元的字串轉換為十六進位值。字串可透過使用pack() 函數再轉換回去。
bin2hex( string )
參數 | 描述 |
---|---|
string | 必需。規定要轉換的字串。 |
傳回值: | 傳回要轉換字串的十六進位值。 |
---|---|
PHP 版本: | 4+ |
把一個字串值從二進制轉換為十六進制,再轉換回去:
<?php$str = "Hello world!";echo bin2hex($str) . "<br>";echo pack("H*",bin2hex($str)) . "<br>";?>