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!");

In above example ,We have string of ASCII characters “Hi from!”. So, when we apply
bin2hex function. This will string of hexadecimal value of input string.

Now Output will become –


bin2hex() with pack() – PHP Functions Example 2 :

If you want to add backslash to mulitiple letters, Use below example :

$strExample = "Hi from!";
echo bin2hex($strExample) . "<br>";
echo pack("H*",bin2hex($strExample));

Output will be like below:

Hi from!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *