Facebook Page Twitter Page LinkedIn Page
× PHP Tutorial PHP Advanced PHP Resources


The PHP String hex2bin() function is used to convert a string containing hexadecimal representation of data into ASCII characters.

Syntax

hex2bin(str)

Parameters

str Required. Specify string containing hexadecimal representation of data.

Return Value

Returns the ASCII characters representation of the given string or false on failure.

Example:

In the below example, hex2bin() function is used to convert the given string containing hexadecimal representation of data into ASCII characters.

<?php
$str = "48656c6c6f20576f726c64";

//converting and printing the hexadecimal 
//data into ASCII characters
echo hex2bin($str);
?>

The output of the above code will be:

Hello World

❮ PHP String functions