Home >Backend Development >PHP Problem >How to convert string to hexadecimal string in php
php method to convert a string to hexadecimal: first create a PHP sample file; then convert the string to 16 by "print(bin2hex($string)."\n");" Just output in hexadecimal format.
Recommended: "PHP Video Tutorial"
You can use the bin2hex function in php to convert a string into 16 hex The bin2hex() function returns the result as ascii code
<?php $string = "Hello\tworld!\n"; print($string."\n"); print(bin2hex($string)."\n"); ?>
The output result is as follows:
Hello world! 48656c6c6f09776f726c64210a
Related introduction:
bin2hex — The function converts binary characters containing data Convert string to hexadecimal value
bin2hex ( string $str ) : string
Convert the binary parameter str into a hexadecimal string. Conversion uses byte mode, with the high nibble taking precedence.
The above is the detailed content of How to convert string to hexadecimal string in php. For more information, please follow other related articles on the PHP Chinese website!