Home > Article > Backend Development > How to use php bin2hex function
bin2hex() function converts a string of ASCII characters into a hexadecimal value. The syntax is bin2hex(string), which accepts a single parameter string and returns the hexadecimal value of the string passed in the parameter.
#How to use php bin2hex() function?
bin2hex() function converts a string of ASCII characters into a hexadecimal value.
Syntax
bin2hex(string)
Parameters:
● string: required. Specifies the string to be converted.
Return value: Returns the hexadecimal value of the string to be converted.
Let’s take a look at how to use the php bin2hex() function through an example.
Example 1:
<?php $data = "hello php.cn"; $res = bin2hex($data); echo $res; ?>
Output:
68656c6c6f207068702e636e
Example 2:
<?php $str1 = "Learning PHP"; echo bin2hex($str1); ?>
Output:
4c6561726e696e6720504850
The above is the detailed content of How to use php bin2hex function. For more information, please follow other related articles on the PHP Chinese website!