Fil*_*efp 16
使用crc32
,它将返回32位int
.
var_dump (crc32 ("hello world"));
var_dump (crc32 ("world hello"));
Run Code Online (Sandbox Code Playgroud)
产量
int(222957957)
int(1292159901)
Run Code Online (Sandbox Code Playgroud)
生成str的32位长度的循环冗余校验和多项式.这通常用于验证传输数据的完整性.
因为PHP的整数类型是有符号的,并且许多crc32校验和将导致负整数,所以需要使用sprintf()或printf()的"%u"格式化程序来获取无符号crc32校验和的字符串表示形式.
phphash()
函数甚至会比crc32()
:
hash("crc32b", $str);
Run Code Online (Sandbox Code Playgroud)
如果需要一个整数:
intval(hash("crc32b", $str), 16);
Run Code Online (Sandbox Code Playgroud)
与 plain 相比crc32()
,它不会受到 32 位和 64 位系统之间有符号/无符号整数不一致的影响(详细信息请参见 PHP 文档:crc32)
ord($hash[0]) * 16777216 + ord($hash[1]) * 65536 + ord($hash[2]) * 256 + ord($hash[3]) ;\n
Run Code Online (Sandbox Code Playgroud)\n\n或者:
\n\nunpack("L", substr($hash,0,4));\n
Run Code Online (Sandbox Code Playgroud)\n\n但 Filip Ros\xc3\xa9en\ 的解决方案更好。
\n