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

How to convert string to hexadecimal string in php

藏色散人
Release: 2023-03-06 11:48:02
Original
4800 people have browsed it

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");
?>
Copy after login

The output result is as follows:

Hello world!
  
48656c6c6f09776f726c64210a
Copy after login

Related introduction:

bin2hex — The function converts binary characters containing data Convert string to hexadecimal value

bin2hex ( string $str ) : string
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template