PHP bin2hex() Function

❮ PHP String Reference

Example

Convert "Hello World!" to hexadecimal values:

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

Definition and Usage

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


Syntax

bin2hex(string)

Parameter Values

Parameter Description
string Required. The string to be converted

Technical Details

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

More Examples

Example

Convert a string value from binary to hex and back:

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

❮ PHP String Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.