It is a function that helps in converting a string into a hexadecimal value. It is done byte wise and the high nibbled bytes are converted first.
Syntax of bin2hex() function
It takes in a string and converts the string to a hexadecimal representation.
<?php $my_str1 = "This"; $my_str2 = "is"; $my_str3 = "a"; $my_str4 = "sample"; print(bin2hex($my_str1)); echo "<br>"; print(bin2hex($my_str2)); echo "<br>"; print(bin2hex($my_str3)); echo "<br>"; print(bin2hex($my_str4)); ?>
54686973 6973 61 73616d706c65
Within the <php> tags, the bin2hex function is called on 4 elements which are previously defined. Then, the result of calling the bin2hex function on each of the string is displayed on the console.