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 = 'Hello';

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

echo $return;

?>
3519fe5ad2c596efe3e276a6f351b8fc0b03db861782490d45f7598ebd0ab5fd5520ed102f38c4a5ec834e98668035fc

2 · binary

<?

$algo = 'sha384';
$data = 'Hello';
$binary = true;

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

echo $return . PHP_EOL . bin2hex($return);

?>
5�Z�Ŗ���v��Q��ۆ�I
E�Y��
��U �/8ĥ�N�f�5�
3519fe5ad2c596efe3e276a6f351b8fc0b03db861782490d45f7598ebd0ab5fd5520ed102f38c4a5ec834e98668035fc

3 · options · empty

<?

$algo = 'sha384';
$data = 'Hello';
$binary = false;
$options = [];

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

echo $return;

?>
3519fe5ad2c596efe3e276a6f351b8fc0b03db861782490d45f7598ebd0ab5fd5520ed102f38c4a5ec834e98668035fc

4 · options · seed

<?

$algo = 'murmur3f';
$data = 'Hello';
$binary = false;
$options = ['seed' => 42];

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

echo $return;

?>
2365fb86a62c2c3ba0c2a44a316b36e2
HomeMenu