String Functions

PHP hex2bin() Function

Topic: PHP String ReferencePrev|Next


The hex2bin() function decodes a hexadecimally encoded binary string.

The following table summarizes the technical details of this function.

Return Value: Returns the binary representation of the given data or FALSE on failure.
Version: PHP 5.4.0+


The basic syntax of the hex2bin() function is given with:


The following example shows the hex2bin() function in action.

// Decoding a hexadecimally encoded binary string
echo hex2bin("48656c6c6f20576f726c6421");

Note: The hex2bin() function does not convert a hexadecimal number to a binary number. This can be done using the base_convert() function.


The hex2bin() function accepts the following parameters.

Parameter Description
string Required. Specifies the hexadecimal representation of data.
Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties