Home >Backend Development >PHP Problem >How to convert string to hexadecimal string in php

How to convert string to hexadecimal string in php

藏色散人
藏色散人Original
2020-10-05 09:49:424813browse

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.

How to convert string to hexadecimal string in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn