bin2hex – PHP String Functions
Syntax :
string bin2hex (string);
Description :
bin2hex function will converts a string of ASCII characters to hexadecimal values. The string can be converted back using the pack() function.
Parameter :
string – String which needs to converted.
Related articles : hex2bin().
Output :
This will returns the hexadecimal value of the converted string.
bin2hex – PHP Functions Example 1 :
$strExample = bin2hex ("Hi from tutorialmines.net!");
echo($strExample);
In above example ,We have string of ASCII characters “Hi from tutorialmines.net!”. So, when we apply
bin2hex function. This will string of hexadecimal value of input string.
Now Output will become –
48692066726f6d207475746f7269616c6d696e65732e6e657421
bin2hex() with pack() – PHP Functions Example 2 :
If you want to add backslash to mulitiple letters, Use below example :
$strExample = "Hi from tutorialmines.net!";
echo bin2hex($strExample) . "<br>";
echo pack("H*",bin2hex($strExample));
Output will be like below:
48692066726f6d207475746f7269616c6d696e65732e6e657421
Hi from tutorialmines.net!