PHP bin2hex()Functions

PHP String 参考手册PHP String Reference Manual

Examples

Convert "Hello World!" to a hexadecimal value:

<?php
$str = bin2hex("Hello World!");
echo($str);
?>

Run Example »

Definition and Usage

The bin2hex() function converts a string of ASCII characters to hexadecimal values. The string can be converted back by using the pack() function.


Syntax

bin2hex(string)

Parameters Description
string Required. Specifies the string to be converted.

Technical Details

Return Value: Returns the hexadecimal value of the string to be converted.
PHP Version: 4+


More Examples

Example 1

Convert a string value from binary to hexadecimal, and then convert it back:

<?php
$str = "Hello world!";
echo bin2hex($str) . "<br>";
echo pack("H*",bin2hex($str)) . "<br>";
?>

Run Example »


PHP String 参考手册PHP String Reference Manual Other Extensions