HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

hash

Description

The hash of Hash for PHP generate a hash value (message digest).

Syntax

hash(
    string $algo,
    string $data,
    bool $binary = false,
    array $options = []
): string

Parameters

algo

Name of selected hashing algorithm.

data

Message to be hashed.

binary

When set to true, outputs raw binary data. false outputs lowercase hexits.

options

An array of options for the various hashing algorithms. Currently, only the "seed" parameter is supported by the MurmurHash variants.

Return

Returns a string containing the calculated message digest as lowercase hexits unless binary is set to true in which case the raw binary representation of the message digest is returned.

Examples

1 · algo data

<?

$algo = "sha384";
$data = "mydata";

$return = hash($algo, $data);

echo $return;
8a40b2c5c3861f6bd1c175adffcb109c84e6e0a7d53f1cb6d698bcc9bbfcbe5d9175fa446a606c8f6e7aaf592ad6ad4c

2 · binary

<?

$algo = "sha384";
$data = "mydata";
$binary = true;

$return = hash($algo, $data, $binary);

echo $return . PHP_EOL
. bin2hex($return);
�@��Æk�u��������?�֘�ɻ��]�u�Dj`l�nz�Y*֭L
8a40b2c5c3861f6bd1c175adffcb109c84e6e0a7d53f1cb6d698bcc9bbfcbe5d9175fa446a606c8f6e7aaf592ad6ad4c

3 · options

<?

$algo = "murmur3f";
$data = "mydata";
$binary = false;
$options =
[
    "seed" => 42
];

$return = hash($algo, $data, $binary, $options);

echo $return;
6fe8494e847d6e3042338f24a3ba653a