Home >>PHP String Functions >PHP hex2bin() Function
The PHP hex2bin() function is used to convert any given input hexadecimal string in to a binary string. PHP hex2bin() function is an in-built function of PHP. This function decodes any binary string which is encoded in hexadecimal value back to it’s binary value.
Hex2bin() function accept only a single parameter $String whichis the given input hexadecimal data which will be decoded to binary.
This bin2hex() function return a string as output which is the binary string of the given hexa-decimal input $String. If the function fails to decode the given hexadecimal string to binary then it returns False as the result.
Syntax:-
hex2bin($String);
Parameter | Description |
---|---|
string | This is a Required parameter. This parameter contains the hexadecimal value that is to be converted into binary |
Here are some examples of hex2bin() function in PHP:
<html> <body> <?php echo hex2bin("50485054504f494e54"); ?> </body> </html>
<html> <body> <?php echo hex2bin("504850206973206120736572766572207369646520736372697074696e67206c616e67756167652e"); ?> </body> </html>