PHP hex2bin is an inbuilt function in PHP. It converts a hexadecimal character sequence back to a binary string. However, it does not convert the hexadecimal string to binary number. In this article, we will discuss the PHP hex2bin Function. Also, we will discuss a few examples of using it.
Also, in order to convert a binary string to its corresponding hexadecimal character sequence, you can use the PHP bin2hex Function.
Remember: There is a very big difference between binary data and a string representation of binary.
Syntax
string hex2bin($hexadecimalString)
Parameters
The function expects only one parameter. The hexadecimal string which needs to be converted to a binary string is the input to the function.
Return Value
The function returns the corresponding binary string after converting the hexadecimal input. However, on failure, it returns false.
Input: hex2bin('636f6e6361746c79') Output: concatly

Example
For instance, consider the following example of using the function.
<?php $hexadecimalString = '636f6e6361746c79'; $binaryString = hex2bin($hexadecimalString); echo $binaryString; ?>
In the above example, the function converts the input hexadecimal string to a binary string. However, the function cannot convert the string to a binary number.
OUTPUT: concatly
Conclusion
In conclusion, we discussed the PHP hex2bin Function. Also, you can read more about it on the Official PHP Documentation. Additionally, you can learn about more PHP String Functions on Concatly.

Vishesh is currently working as an Intermediate Software Engineer with Orion Health, New Zealand. He graduated with a Masters in Information Technology from the University of Auckland in 2021. With more than 4 years of work experience, his expertise includes Java, Python, Machine Learning, PHP, Databases, Design and Architecture.