hex2bin()
hex2bin() — Decodes a hexadecimally encoded binary string.
Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.4.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
Signature
hex2bin(string $string): string|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $string | string | Hexadecimal representation of data. |
Return value
Returns the binary representation of the given data or false on failure.
Example
A runnable snippet:
$hex = hex2bin("6578616d706c65206865782064617461"); var_dump($hex);
Output:
string(16) "example hex data"
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page hex2bin() (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.