bin2hex

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

bin2hexConvert binary data into hexadecimal representation

Опис

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.

Параметри

string

A string.

Значення, що повертаються

Returns the hexadecimal representation of the given string.

Приклади

Приклад #1 bin2hex() example

<?php

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

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

Поданий вище приклад виведе:

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

Прогляньте також

  • hex2bin() - Decodes a hexadecimally encoded binary string
  • pack() - Pack data into binary string