PHP hex2bin() Function
Topic: PHP String ReferencePrev|Next
Description
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+ |
Syntax
The basic syntax of the hex2bin() function is given with:
hex2bin(string);
The following example shows the hex2bin() function in action.
Example
Run this code »<?php
// 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.
Parameters
The hex2bin() function accepts the following parameters.
| Parameter | Description |
|---|---|
| string | Required. Specifies the hexadecimal representation of data. |

