PHP hex2bin() Function

Example

Convert hexadecimal values to ASCII characters:

<?php
echo hex2bin("48656c6c6f20576f726c6421");
?>

Output of the above code:

Hello World!

Definition and Usage

The hex2bin() function converts a string of hexadecimal values to ASCII characters.

Syntax

hex2bin(string)
Parameter Description
string Required. The hexadecimal value to be converted.

Technical Details

Return Value: Returns the ASCII character of the converted string, or FALSE if the conversion fails.
PHP Version: 5.4.0+
Update Log:

Since PHP 5.4.1, a warning is thrown if the string length is odd. In PHP 5.4.0, odd string lengths were silently accepted, but the last byte was removed.

Since PHP 5.5.1, a warning is thrown if the string is an invalid hexadecimal string.