bin2hex()
bin2hex() — Convert binary data into hexadecimal representation.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Returns an ASCII string containing the hexadecimal representation of string. The conversion is done byte-wise with the high-nibble first.
Signature
bin2hex(string $string): string
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $string | string | A string. |
Return value
Returns the hexadecimal representation of the given string.
Example
A runnable snippet:
$hex = bin2hex('Hello world!'); var_dump($hex); var_dump(hex2bin($hex));
Output:
string(24) "48656c6c6f20776f726c6421" string(12) "Hello world!"
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page bin2hex() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.