PHP bin2hex() function
Example
Convert "Shanghai" to hexadecimal value:
<?php $str = bin2hex("Shanghai"); echo($str); ?>
Definition and Usage
The bin2hex() function converts a string of ASCII characters to hexadecimal values. The string can be converted back using the pack() function.
Syntax
bin2hex(string)
Parameter | Description |
---|---|
string | Required. The string to be converted. |
Technical Details
Return Value: | Return the hexadecimal value of the string to be converted. |
PHP Version: | 4+ |
More Examples
Example 1
Convert a string value from binary to hexadecimal and back:
<?php $str = "Shanghai"; echo bin2hex($str) . "<br>"; echo pack("H*",bin2hex($str)) . "<br>"; ?>