PHP Function Reference

PHP bin2hex() Function



The PHP bin2hex() function is used to convert a string of ASCII characters into hexadecimal representation.

Syntax

bin2hex(str)

Parameters

str Required. Specify the string to be converted.

Return Value

Returns the hexadecimal representation of a string of ASCII characters.

Example:

In the example below, bin2hex() function is used to convert the given string of ASCII characters into hexadecimal representation.

<?php
$str = "Hello World";

//converting and printing the ASCII data 
//into hexadecimal representation
echo bin2hex($str);
?>

The output of the above code will be:

48656c6c6f20576f726c64

❮ PHP String Reference