php8.5
Home/ Manual/ strings / functions/ bin2hex

bin2hex

PHP function Edit on GitHub ✎

(PHP 4, PHP 5, PHP 7, PHP 8)

Convert binary data into hexadecimal representation

Description

bin2hex(string $string): string

Returns an ASCII string containing the hexadecimal representation of string. The conversion is done byte-wise with the high-nibble first.

Parameters

string

A string.

Return Values

Returns the hexadecimal representation of the given string.

Examples

bin2hex() example

php
<?php

$hex = bin2hex('Hello world!');

var_dump($hex);
var_dump(hex2bin($hex));
?>

The above example will output:

output
string(24) "48656c6c6f20776f726c6421"
string(12) "Hello world!"

See Also

Source: reference/strings/functions/bin2hex.xml · from the official PHP manual (php/doc-en)