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

sha1

Description

Calculate the sha1 hash of a string

Syntax

sha1(
    string $string,
    bool $binary = false
): string

Parameters

string

The input string.

binary

If the optional binary is set to true, then the sha1 digest is instead returned in raw binary format with a length of 20, otherwise the returned value is a 40-character hexadecimal number.

Return

Returns the sha1 hash as a string.

Examples

1 · string

<?

$string = 'hello';

$return = sha1($string);

echo $return;

?>
aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d

2 · binary

<?

$string = 'hello';
$binary = true;

$return = sha1($string, $binary);

echo $return . PHP_EOL;

$unpack = unpack('H*', $return);

$array_pop = array_pop($unpack);

echo $array_pop;

?>
������ھ�;H,ٮ�CM
aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
HomeMenu