Convert "Hello World!" to a hexadecimal value:
<?php $str = bin2hex("Hello World!");echo($str); ?>The bin2hex() function converts a string of ASCII characters into a hexadecimal value. Strings can be converted back using the pack() function.
bin2hex( string )
parameter | describe |
---|---|
string | Required. Specifies the string to be converted. |
Return value: | Returns the hexadecimal value of the string to be converted. |
---|---|
PHP version: | 4+ |
Convert a string value from binary to hexadecimal and back again:
<?php$str = "Hello world!";echo bin2hex($str) . "<br>";echo pack("H*",bin2hex($str)) . "<br>";?>