小白教程
所有教程
关于
Search
172.71.254.250
172.71.254.250
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Func string sha1”的源代码
本页内容
上一节:
Func_string_setlocale
下一节:
Func_string_sha1_file
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:sha1()}}[[分类:PHP字符串函数参考手册|46]] = PHP sha1() 函数 = [[:分类:PHP字符串函数参考手册]] 计算字符串 "Hello" 的 SHA-1 散列: <sample title="" desc="" lang="php" hererun="1"> <?php $str = "Hello"; echo sha1($str); ?> </sample> == 定义和用法 == sha1() 函数计算字符串的 SHA-1 散列。 sha1() 函数使用美国 Secure Hash 算法 1。 来自 RFC 3174 的解释 - 美国 Secure Hash 算法 1:SHA-1 产生一个名为报文摘要的 160 位的输出。报文摘要可以被输入到一个可生成或验证报文签名的签名算法。对报文摘要进行签名,而不是对报文进行签名,这样可以提高进程效率,因为报文摘要的大小通常比报文要小很多。数字签名的验证者必须像数字签名的创建者一样,使用相同的散列算法。 '''提示:'''如需计算文件的 SHA-1 散列,请使用 [[func string sha1 file|sha1_file()]] 函数。 == 语法 == <pre> sha1(string,raw) </pre> {| class="table table-striped table-hover" !width="50%"| 参数 !width="50%"| 描述 |- | string | 必需。规定要计算的字符串。 |- | raw | 可选。规定十六进制或二进制输出格式: * TRUE - 原始 20 字符二进制格式 * FALSE - 默认。40 字符十六进制数 |} == 技术细节 == {| class="table table-striped table-hover" | 返回值: | 如果成功则返回已计算的 SHA-1 散列,如果失败则返回 FALSE。 |- | PHP 版本: | 4.3.0+ |- | 更新日志: | 在 PHP 5.0 中,raw 参数变成可选的。 |} == 更多实例 == == 实例 1 == 输出 sha1() 的结果: <sample title="" desc="" lang="php" hererun="1"> <?php $str = "Hello"; echo "The string: ".$str."<br>"; echo "TRUE - Raw 20 character binary format: ".sha1($str, TRUE)."<br>"; echo "FALSE - 40 character hex number: ".sha1($str)."<br>"; ?> </sample> == 实例 2 == 输出 sha1() 的结果并对它进行测试: <sample title="" desc="" lang="php" hererun="1"> <?php $str = "Hello"; echo sha1($str); if (sha1($str) == "f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0") { echo "<br>Hello world!"; exit; } ?> </sample> [[:分类:PHP字符串函数参考手册]]
返回至“
Func string sha1
”。
上一节:
Func_string_setlocale
下一节:
Func_string_sha1_file