函数名:hash()
适用版本:PHP 5 >= 5.1.2, PHP 7, PHP 8
用法:hash(string $algo, string $data, bool $raw_output = false): string|false
说明:hash() 函数用于计算字符串的哈希值。它采用指定的算法对数据进行哈希计算,并返回哈希值。
参数:
返回值:
示例:
// 使用 MD5 算法计算哈希值
$hash = hash('md5', 'Hello World');
echo $hash; // 输出:ed076287532e86365e841e92bfc50d8c
// 使用 SHA256 算法计算哈希值(返回原始二进制数据)
$hash = hash('sha256', 'Hello World', true);
echo bin2hex($hash); // 输出:2ef7bde608ce5404e97d5f042f95f89f1c232871a9cf1b44ee5dbe2b7cc4e9d6
注意事项: